On Sep 13, 2009, at 9:11 PM, Andre van Tonder wrote:

> On Sun, 13 Sep 2009, Abdulaziz Ghuloum wrote:
>
>>
>> On Sep 11, 2009, at 7:59 PM, Andre van Tonder wrote:
>>
>>> As far as macro expansion is concerned, I contend that the choice
>>> between one-pass or two-pass is really arbitrary.
>>
>> Can we clarify the terminology here please:
>>
>> * one-pass: each definition's right-hand-side expression is fully
>> expanded (and macro definitions are expanded and evaluated) before
>> the expander moves to the following definition/expression in body.
>> [the repl /must/ use this because it does not have access to the
>>  whole program]
>>
>> * two-pass: each variable definition's rhs expression is deferred
>> until all definitions are accounted for; each syntax definition is
>> expanded and evaluated; and each macro use is expanded and its
>> result is used to replace the macro form; and once a nondefinition
>> is encountered in body, all deferred expressions are expanded.
>> [internal/library/program definitions /can/ use this because the
>>  whole body is known in advance]
>>
>> Is this correct?
>
> I think so, except that I don't think your description of two-pass
> is correct for R6RS toplevel programs, where definitions
> can follow non-definitions.

Yes, I glossed over that.  But it's essentially "two-pass" since
you don't expand these expressions when you see them, but defer
them until all definitions are accounted for.  So, basically,

* one-pass: expands expressions as they're encountered.
* two-pass: expands expressions until all definitions are found.

> Are you aware of any advantages in expressiveness of the two-pass
> that cannot be reproduced by rearrangement?

I think one-pass gives you an approximation of let*-scoping
semantics while two-pass gives you recursive bindings.  For
example, the following expression

(let-syntax ((f (syntax-rules () ((_) 1))))
   (let ()
     (define (g) (f))
     (define (f) 2)
     (g)))

evaluates to 1 in one-pass since at the time (f) is expanded,
only the outer f is known.  In two-pass, it evaluates to 2
since (f) is expanded after the shadowing definition of f is
found.

Did I miss something?

Aziz,,,

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to