[plt-scheme] define-for-syntax mutual recursion

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jun 1 07:45:14 EDT 2009

At Mon, 1 Jun 2009 01:02:54 -0400, Anthony Cowley wrote:
> Is there any explanation for why  
> this is necessary, though? It seems natural to expect the define-for- 
> syntax
> form to work like define.

It has to do with the order of expansion. In the case of a plain
`define', the macro expander can delay expanding the RHS of the
`define' until it has seen all of the module's other top-level forms,
so it knows all available bindings by the time it expands an
expression. Values bound with `define-for-syntax', however, can be used
for expanding later top-level forms in the module, so the RHS must be
expanded and evaluated right away.

I think there must be a way to define expansion and evaluation to allow
mutually dependent `define-for-syntax' forms (e.g., complain only if a
not-yet-defined identifier is actually used before it is defined, and
also check for references to undefined identifiers at the end of the
module body instead of when each RHS is compiled), but I never got
around to refining the expander in that direction.



Posted on the users mailing list.