On Tue, 2009-09-15 at 09:17 -0500, Brian Mastenbrook wrote:
> On Sep 15, 2009, at 6:45 AM, Andre van Tonder wrote:
> 
> > On Mon, 14 Sep 2009, Brian Mastenbrook wrote:
> >
> >> (define b 1)
> >> (begin
> >>  (define a b)
> >>  (define b 2)) -> error, attempt to use `b' before its definition
> >
> > This is certainly incorrect behavior in R5RS.
> 
> 
> The question is: is this behavior sensible?

I don't think so.  "error, attempt to define b more than once" is 
consistent, but "error, attempt to use b before its definition" 
is not.  

>  Was the conflation of  
> binding and mutation at the top-level into one syntax ever a good idea  
> in the first place - especially when the SAME syntax is used only for  
> binding elsewhere?

There is no mutation involved in the above code snippet.  What we 
have here is a conflation of binding and sequencing. BEGIN is 
properly a sequencing primitive, and as such there is no good reason 
why it needs to have any effect on scope. 

On the contrary, if BEGIN establishes a scope, then firstly it 
is redundant and should be eliminated because the only semantics 
it could then express are expressible by one of the various let 
and let-foo forms.  

Secondly, the language needs a primitive for bundling multiple 
forms which does not establish a scope, for purposes of allowing 
macros to expand into multiple forms (typically definitions) 
when those forms must be in the same scope as the call site.

There is no absolute reason why the primitive for bundling 
multiple forms has to also be a sequencing primitive. But it's 
usually convenient for it to be so, and as long as mutation 
exists, we need a sequencing primitive, and as far as I know 
no one has demonstrated any reason for the sequencing and 
bundling primitives to be distinct. 

> Would anyone who is not doing "screwy" things with macros ever notice  
> the difference? 

Absolutely.  It is not at all screwy to have (and need!) a single 
macro invocation to expand into multiple definitions.  See the 
highly useful object library 'Meroon,' which was written by 
Christian Queinnec and featured in his excellent book
(_Les_Langages_Lisp_ in French, _Lisp_In_Small_Pieces_ in English) 
for a widespread example of macros in a library that a lot of 
people actually do use.  It would break horribly if begin 
contained its definitions in a local scope, and more importantly, 
there would be no way to fix it because without an open-scoped  
bundling primitive there would be no way left to implement it 
in Scheme. 

                                Bear






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

Reply via email to