[R6RS] Internal DEFINE vs. macros

dyb at cs.indiana.edu dyb
Tue Apr 12 11:20:15 EDT 2005

> Kent> [...] I agree that making top-level and internal contexts behave
> Kent> similarly would be useful.  What people usually mean by this is
> Kent> that internal contexts should behave like their favorite Scheme
> Kent> system's interactive top-level environment behaves [...]
> Ah, sorry, I should have said that more precisely:
> I didn't mean the interactive top-level, but rather the outermost
> level of the core language.  This is inherently different from
> internal contexts because of shadowing.  The semantics of this should
> be specified as precisely as that of internal contexts for the same
> reasons.

But I thought your notion of core language did not include top-level
definitions, just module forms.  Forgive me from being dense, but doesn't
this mean that all definitions are internal?

> Kent> Yes, I can and will if I end up writing up a syntax-case
> Kent> proposal more formally.  I believe it can be reasonably simple.
> Will that end up describing what Chez currently does?  This kind of
> dichotomy confuses me, leaving aside for a moment the issue of
> ambiguity:
> (let-syntax ((bar (syntax-rules ()      (let ((bar					 
> 		    ((bar) 'outer))))          (lambda () 'outer)))			 
>   (define-syntax bar                      (define bar					 
>     (syntax-rules ()                        (lambda ()					 
>       ((bar) 'inner)))                        'inner))					 
>   (bar))                                  (bar))
>    => 'outer                               => 'inner
> Can you give a preview of how to explain this behavior?

I think you are running up against the fact that Chez Scheme does
not treat the forms within a let-syntax and letrec-syntax as bodies;
instead, let-syntax and letrec-syntax are treated like begin.  This allows
let-syntax and letrec-syntax forms to be treated as definitions in the
same sense that begin is treated as a definition.

The example would be written instead like this:

(let-syntax ((bar (syntax-rules () ((bar) 'outer))))
  (let ()
    (define-syntax bar (syntax-rules () ((bar) 'inner)))
-> 'outer


More information about the R6RS mailing list