On Tue, 15 Sep 2009 10:17:52 -0400, Brian Mastenbrook
<[email protected]> 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? 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?
>
> Would anyone who is not doing "screwy" things with macros ever notice
> the difference? How often do you type (begin ...) at the REPL anyway?
>
> Wouldn't it be better if `define' *always* behaved as binding, and
> never as mutation?
Treating DEFINE as mutation on the REPL can be a little useful in that we
can assume all names are bound, and this can help with defining some
procedures that use values that have not yet been bound. This is, I
believe, only one way of doing it, however.
Keep in mind that the desired semantics in a perfect world are closer to
the internal library body in R6RS or the top-level program semantics, and
the semantics of the REPL are an unfortunate necessity because we must
evaluate every form that we encounter as we encounter it. It is much nicer
to be able to evaluate each definition in the same scope and have LETREC
or LETREC* semantics. Thus, the fact that we have an immediate evaluation
limitation on the REPL should not be unnecessarily extended to places
where we need not limit our code so. BEGIN is such a case. Because we get
an *entire* BEGIN clause as a single unit, we can take advantage of
evaluating them all as they really ought to be evaluated, rather than
condescending to a less ideal REPL semantics. This is a good thing, imo.
That is, a begin form with multiple definitions does not inherently suffer
from the limitation of needing to evaluate each definition before
examining the next, and so we should not apply the restriction. This
restriction is not in place when BEGIN is used in the body of a top-level
program or a library form, so we should we enforce the restriction
needlessly in the REPL? It's only a bother, not a help.
Aaron W. Hsu
--
Of all tyrannies, a tyranny sincerely exercised for the good of its
victims may be the most oppressive. -- C. S. Lewis
_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss