Wednesday, 2 October 2013

unbound identifier and no #%top syntax transformer

unbound identifier and no #%top syntax transformer

I'm playing around with a fluent interface (for a pretty strange
definition of fluent) so that I can learn about racket macros better, so I
mocked up this code to play with.
#lang racket
(require racket/syntax)
(struct Person (name location))
(define-syntax what
(syntax-rules (is)
((what is x thing) (what is x's thing))
((what is x quote-s thing)
(let* ((x-str (~a (quote x)))
(x-id (format-id #'x-id "~a" x-str))
(thing-str (~a (quote thing)))
(thing-proper-str (cadr (regexp-match #rx"(.*)\\?" thing-str)))
(thing-id (format-id #'thing-id "Person-~a" thing-proper-str)))
((eval thing-id) (eval (syntax-e x-id)))))))
(define John (Person "John Luser" "Here"))
(what is John's name?)
Running this results in John: unbound identifier; also, no #%top syntax
transformer is bound in: John. If I had to guess, I'd say that all the
putzing around I do with identifiers and strings strips the symbol John of
its binding, or that I'm evaling in the wrong environment, but I don't
know how to fix either of those.

No comments:

Post a Comment