'Treating macros like normal functions in Racket

Aim

I'm trying to read lists of (relationship-name src-name tgt-name) entities into racklog ( src ). Racklog's %rel wants pairs hand-written as syntax.

In a language like J.Shutt's Kernel it's trivial to treat 'special forms' (operatives like let, if) as typical functions (applicatives) via wrap and unwrap. Racklog does not seem to provide any unwrapped variants of %rel

(define (knows-facts (
  list 
  [("Bob" "TeX")]
  [("Bob" "Lisp")]
  [("Alice" "Lisp")]
  [("Alice" "Prolog")])))

(define knows
  (rel-but-less-handwritten knows-facts))

(define which-query (lambda (rel, what)
  (rel 'Bob what)))

(which-but-less-handwritten knows (lambda (rel, what) 
  (rel 'Bob what)))

How can I implement these example cases of rel-but-less-handwritten, which-but-less-handwritten, and more generally how can I use racket macros as regular functions?

Current Code

; copy paste, I believe this dynamically binds a custom namespace as
; `current-namespace` and adds racklog, then evals in this namespace context
(define my-eval
  (let ([ns (make-base-namespace)])
    (parameterize ([current-namespace ns]) (namespace-require 'racklog))
    (lambda (expr) (eval expr ns))))

; pairs is a normal list of ('Man 'Mortal) pairs like racklog expects
; to be hand-written. I want to supply them via variable, not hand-written, since
; I'm loading these pairs from a file. So creating an expression dynamically
(define relationship-value (append (quasiquote (%rel ())) (map list pairs)))

; value is now bound to a racklog predicate
(define value (my-eval relationship-value))

I then created a hash that gives names for these predicates (e.g %knows, %is, %has, etc).

which causes call-cc to fail

call-with-current-continuation: no corresponding prompt in the continuation
  tag: #<continuation-prompt-tag:racklog>
  context...:
   /usr/share/racket/pkgs/racklog/racklog.rkt:95:8
   body of "/home/rg/Code/Axon/axon.rkt"
zsh returned exit code 1

Edit

@ Sorawee Porncharoenwase

The list of triples is computed by reading from a database, though if it's essential I can store them 'statically' in a file as an intermediate step.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source