[racket] datum<->syntax with same context, yet "unbound identifier"

From: Greg Hendershott (greghendershott at gmail.com)
Date: Wed Nov 21 09:33:06 EST 2012

> The lexical context you're picking up to put on #'args in the lam
> macro is the context that's sitting on the parentheses in the first
> argument to 'lam' in the body of 'expand-to-lam'. that context has no
> "x" bound.

OK, that explains why x is not bound. Thanks!

> This is the trouble with these kinds of macros: you have to be careful
> to propagate the correct lexical information thru. In this case, you
> can either change expand-to-lam to carry its argument's lexical
> context onto that open paren there or you can change lam to use a
> different spot to get its lexical information (one that's already
> being carried thru, eg the context on the actual variables for
> example).

I want lam to be usable by other macros without the latter needing to
cooperate explicitly; I want them to "just work". So I prefer the
second way.

But isn't that what I'm already doing by supplying #'args to datum->syntax?

  (datum->syntax #'args (append (syntax->datum #'args)))

I don't see how else to get "the context on the actual variables". The
only other choice seems to be `stx', which also doesn't work.

> The model in the JFP paper should shed some light on this, I hope. (I
> seem to recall you looking at that before?)

I did read it and found it helpful to appreciate what the Racket macro
system has to do and how. But I guess I didn't grok it enough to be
able to apply it, here. The lightbulb is flickering but not really on,
yet.

Posted on the users mailing list.