[racket] macros whose meaning is dependent on context?

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Oct 16 18:40:25 EDT 2012

A few minutes ago, John Clements wrote:
> On Oct 16, 2012, at 3:25 PM, Jon Rafkind wrote:
> > This is what syntax-parameters are for.
> > 
> > (require racket/stxparam)
> > (define-syntax-parameter m (lambda (stx) (raise-syntax-error 'm "dont use this outside deeper")))
> > 
> > (define-syntax-rule (deeper e)
> >    (syntax-parameterize ([m (lambda (stx) #'1)])
> >       e))
> > 
> > (deeper (m)) -> 1
> Okay, this makes sense; I'm just deeply freaked out (temporarily, I
> presume) that the syntax-parameterize occurs in the phase 0 code,
> and not the phase 1 code; rather than doing the transformation that
> I want to do during the evaluation of the macro, I'm embedding it in
> another macro, to be evaluated later.

It doesn't -- it's just like a definition of a macro that is bound at
0 but the actual value is at 1.  And BTW, while the syntax parameters
are mostly used as macros, you can also bind them to any value and use
`syntax-parameter-value' which is similar to `syntax-local-value' for
grabbing the actual (phase 1) value.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.