[r6rs-discuss] Expansion process

AndrevanTonder andre at het.brown.edu
Fri Feb 23 07:32:17 EST 2007


On Thu, 22 Feb 2007, Per Bothner wrote:

> AndrevanTonder wrote:

>> On Thu, 22 Feb 2007, Per Bothner wrote:
>>
>>>  (define VAR (MAC))
>>>  (set! VAR (MAC))
>>>  (list (MAC))
>>>  (MAC)
>>>  (define-syntax MAC ...)
>>> 
>>> The first 3 (MAC) applications are deferred, so are correctly
>>> done using the following the define-syntax.
>>> The 4th (MAC) is not deferred, and so "the wrong thing will
>>> happen".
>> 
>> Not in a correct implementation.  A correct implementation should throw a 
>> syntax error.
>
> I'm missing something here.  Is this an argument against my point?
> My reading of the statement you quoted is that the first 3 forms are
> valid, and the 4th should be a syntax error...
>
> You agree that:
>  (car (list (MAC))
> is valid while:
>  (MAC)
> is a syntax violation?

No, technically the syntax error happens when the 5th form
(define-syntax MAC ....) is processed.

A good reason for this is that sequences such as

   (MAC)
   (define-syntax MAC ....)

are incompatible with the single-pass left-to-right algorithm for discovery of 
definitions, since the second line might define (MAC) to expand to definitions 
after the first line has already been processed.  We have 
the following options for the definition discovery part of the algorithm as 
applied to the above sequence:

  (1) Use a multi-pass algorithm for discovering definitions
  (2) Use a single-pass algorithm and possibly violate lexical scoping
  (3) Use a single-pass algorithm but raise a syntax error

Given a choice between (2) and (3), I think (3) is less "wrong" than (2).

Cheers
Andre




More information about the r6rs-discuss mailing list