Oh, good point! Yes, that sounds like it should work well, sorry I didn't think of it.<div><br></div><div>Robby<br><br>On Wednesday, November 21, 2012, Tobias Hammer wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wed, 21 Nov 2012 15:33:06 +0100, Greg Hendershott <<a>greghendershott@gmail.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The lexical context you're picking up to put on #'args in the lam<br>
macro is the context that's sitting on the parentheses in the first<br>
argument to 'lam' in the body of 'expand-to-lam'. that context has no<br>
"x" bound.<br>
</blockquote>
<br>
OK, that explains why x is not bound. Thanks!<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This is the trouble with these kinds of macros: you have to be careful<br>
to propagate the correct lexical information thru. In this case, you<br>
can either change expand-to-lam to carry its argument's lexical<br>
context onto that open paren there or you can change lam to use a<br>
different spot to get its lexical information (one that's already<br>
being carried thru, eg the context on the actual variables for<br>
example).<br>
</blockquote>
<br>
I want lam to be usable by other macros without the latter needing to<br>
cooperate explicitly; I want them to "just work". So I prefer the<br>
second way.<br>
</blockquote>
<br>
As Robby explained you are using the context of the list of args for all arguments,<br>
which is in this case a wrong one. One context that should be valid in all cases<br>
in your example is the one of the arguments itself. If you unpack the<br>
arguments, do whatever you want to them and then reapply the context you stripped before,<br>
it should (as far as i understand) work:<br>
<br>
(define-syntax (lam stx)<br>
(syntax-case stx ()<br>
[(_ args body ...)<br>
(with-syntax ([conv-args (for/list ([a (syntax->list #'args)])<br>
(define a-datum (syntax->datum a))<br>
;; do whatever you want with a-datum<br>
(datum->syntax a a-datum))])<br>
#`(lambda conv-args<br>
body ...))]))<br>
<br>
Other macros only have to cooperate in the 'normal' way, i.e. they have to make sure<br>
that the arguments they pass in have the right context.<br>
<br>
Tobias<br>
</blockquote></div>