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

From: Jim Witte (jswitte at bloomington.in.us)
Date: Wed Oct 29 23:30:53 EST 2003


   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:


   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.