[ERR5RS] Rationale and ease of use

AndrevanTonder andre at het.brown.edu
Sat Sep 8 10:54:54 PDT 2007


On Sat, 8 Sep 2007, Lynn Winebarger wrote:

> suppose the intent was to remove some layers of nesting, but the effect in
> R6RS has been taken to the extreme - top-level defines have been redefined
> to be consistent with internal defines!

No.  Actually R6RS internal definitions are now consistent with *R5RS* toplevel 
definitions (except for forbidding internal redefintions, which R5RS also did).
So R6RS is more consistent with R5RS than R5RS was with itself ;-)

> (define bar 1)
> (define foo
>   (lamdba (x)
>      (if x
>          (define bar 100)
>          (set! bar (+ bar 1)))
>      #t)))
>
> There is one sensible, consistent way to interpret this code, which is that
> the (define bar 100) establishes a global binding of bar, not a local one.

No.  Even if you could have a definition as a branch of IF (which you cannot), 
the LAMBDA introduces a local scope, so assuming that DEFINE is a binding 
form, the inner BAR would not be visible to the toplevel.  The concept of local 
scope has been part of Scheme forever and is in fact part of the original 
raison d'etre of Scheme.

> the top-level definitions (in the presence of syntax-case, anyway) are
> effectively evaluated in phases above the expansion of all subsequent
> expressions, with bindings shared in downward phases.

This is only true in a REPL setting.  To extend this to a compiler-only 
Scheme implementation is possible, but would require the compiler to evaluate
each definition before continuing to compile subsequent expressions.
Imagine the following program:

   (define pi-to-four-billion-digits
     (calculation-taking-40-days))

   (define-syntax format-result
     (lambda (e) (syntax-case e -----)))

   (format-result pi-to-four-billion-digits)

Adopting your suggestion, /compiling/ this program will take 40 days.  And then
you have not even run it.

> It is a shame
> R6RS will not explicitly state what programs will have a definite meaning,
> and explicitly leave the rest undefined.

Exactly!

> (define bar 10)
> (define-syntax foo
>  (lambda (x)
>     (define bar 'a)
>     (syntax-case x ()
>       ((_) #'bar)
>       ((_ y) #'(set! bar y)))))))

Again, the lambda introduces a local scope, so the inner definition of BAR 
cannot modify the outer BAR (since forever in Scheme).

Andre



More information about the Err5rs mailing list