[racket] Understanding lexical context

From: Greg Hendershott (greghendershott at gmail.com)
Date: Tue Oct 1 15:01:33 EDT 2013


Maybe the following question won't make any sense after I've digested
the implications, but to ask anyway:

I'm completely sold on "keeping it clean", and for example using
syntax parameters when possible.

That leaves at least one use case, which is what I'll call (not
knowing a better phrase) defining-things macros.  Like what `struct`
does when defining field accessors, and like my toy hyphen-define
example does. This seems like a really, really common use case for

Is there a generically safe/sane way to write such macros?

Could some mechanism be devised to help do this -- much like
syntax-parameters enables you to write anaphoric-if and friends

On Tue, Oct 1, 2013 at 2:48 PM, Sam Tobin-Hochstadt
<samth at cs.indiana.edu> wrote:
> On Tue, Oct 1, 2013 at 2:42 PM, Greg Hendershott
> <greghendershott at gmail.com> wrote:
>> 2. Plus it seems like it would be really unfortunate if carefully
>> choosing one of #'a or #'b were required -- because that would mean
>> `inner` couldn't be written to be usable by other macros independent
>> of knowing the origin of what they give to `inner`, right?  I mean,
>> without knowing if a comes from `outer` or from the usage of `outer`,
>> and likewise for b, and therefore which of a or b to choose carefully.
> Carefully choosing one _is_ required, and it _is_ really unfortunate.
> This is, in essence, why unhygenic macros are bad for composition. You
> have to pick something as the lexical context of your identifiers, and
> your choices are limited to (a) one of the syntax objects in your
> input or (b) whatever the previous expansion step was (that's what
> syntax-local-introduce does). Therefore, it's hard to compose them
> because they have to have a specific protocol for choosing identifier
> contexts, and if the protocols don't line up, everything becomes much
> more painful.
> Sam

Posted on the users mailing list.