[racket-dev] some surprising behavior with syntax-parameterize and lexical info

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Apr 5 21:42:00 EDT 2012

At Thu, 05 Apr 2012 17:34:54 -0600, Michael W wrote:
> Hey wow, maybe I might understand this. Or maybe I might be
> totally wrong. Here's a guess:
> 
> In the first version, the (splicing-syntax-parameterize) takes
> effect *when f is defined*; [...]
> 
> But in the second version, the splicing-syntax-parameterize takes
> effect during the dynamic extent of the function call, [...]
> 
> Maybe something like that?

You may be getting at the answer, but I wouldn't describe it that way.
I would say that the effect (if that's the right word) of
`syntax-parameterize' is always static.


At Thu, 5 Apr 2012 16:15:36 -0400, Danny Yoo wrote:
> The only difference is that the use of splicing-syntax-parameterize
> has been moved closer to the body expressions.  I expected these two
> programs to show the same output (84), but they don't.  Does anyone
> know why?

With

   (splicing-syntax-parameterize ([current-def #'lexical-stx])
     (define (name arg ...)
        body ...))

then the syntax object created by #'lexical-stx has a lexical context
that doesn't include the `arg's. If an `arg' is `x', and it you
transfer the context to of #'lexical-stx to a symbol 'x through a macro
in a `body', then the created `x' doesn't see the binding that
corresponds to the `arg'.

With 

   (define (name arg ...)
     (splicing-syntax-parameterize ([current-def #'lexical-stx])
        body ...))

the syntax object created by #'lexical-stx does have a lexical context
that includes the `arg's. So, if you transfer that context to a symbol
that matches an `arg' in a macro within `body', then it sees the
binding.


If that doesn't seem clear, can you explain more your line of reasoning
that they should be the same?


Posted on the dev mailing list.