[plt-scheme] Using one defined syntax from inside other defined syntax

From: Robby Findler (robby at cs.uchicago.edu)
Date: Thu Oct 30 07:13:46 EST 2003

This kind of thing:

(define (g x) (syntax 1))
(define-syntax (f stx) (g stx))

Is disallowed in mzscheme's macro system, if that's what you're asking.
Have a look at this paper:

  http://www.cs.utah.edu/plt/publications/macromod.pdf

for why and what you can do instead.

Robby

At Wed, 29 Oct 2003 23:30:53 -0500, Jim Witte wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Hi,
> 
>    Can you use lambdas and syntax transformers you've defined from 
> within the body of other syntax transformers, if those transformers 
> appear *inside* other defined lambda?  I'm trying to figure out why 
> ParentheC (a *very* simply scheme-to-C conversion program; look at 
> http://www.cs.indiana.edu/classes/c311/notes.html) doesn't work under 
> DrScheme (it works under Chez).
> 
>    The file ParentheC.ss defines several syntax extensions for defining 
> unions of expressions and function definitions.  The first error that 
> pops up is that one syntax-case transformer (which is inside the lambda 
> expression define-union) references a lambda defined earlier 
> (robust-syntax:unions).  The define-union syntax is used as follows:
> 
> (define-union exp
>    (const c)
>    (var x)
>    ...)
> 
>    Where exp is a tag for a particular type of union, and the lists 
> after it are different forms it can take (in (<tag> <var ...>) form).  
> The code for what each of these cases does is defined using a different 
> syntax-definition, union-case.  Sample code that will compile under 
> Chez with ParentheC can be found at:
> 
> http://www.cs.indiana.edu/l/www/classes/c311/ass9.html
> 
>    Using a lambda from within an "ordinary" (top-level) syntax-rules 
> definition works in DrScheme, but I really haven't a clue how a 
> syntax-case definition that's inside a lambda should behave, or why a 
> reference to an outside lambda wouldn't work from within such a 
> transformer.  If I bring the definition for r obust-syntax:unions 
> inside the define-union lambda, that error disappears, but another one 
> (involving the function valid-symbol-set) pops up.  I suppose I could 
> stick all the functions used by define-union inside the lambda, but 
> some if not all of these functions are used by the other syntax 
> transformers.  Is this apparent access to top-level definitions from 
> within transformers (but apparently only one's that appear within other 
> lambdas..) an extension of Chez that isn't standard RSR5?
> 
> Student of Dan "bend-your-mind" Friedman..
> Jim Witte
> 
> 



Posted on the users mailing list.