[ERR5RS] Rationale and ease of use
David Rush
kumoyuki at gmail.com
Tue Sep 11 02:36:41 PDT 2007
On 9/11/07, Lynn Winebarger <owinebar at gmail.com> wrote:
> On 9/8/07, AndrevanTonder <andre at het.brown.edu> wrote:
> > 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 ;-)
>
> R5.97RS has the following mandate for top-level defines (from
> http://www.r6rs.org/document/html-5.97/r6rs-Z-H-13.html#node_chap_10
> ) :
ICK! I'd read this before but never went deeper than my keyword
scanner in checking for observable semantic changes. This is *far* too
detailed. Somewhere on the Wiki, I rather flippantly suggested that we
just admit that we have a lisp equivalent of CPP, but this verbage
enshrines it in a maze of twisty spaghetti-semantics, all alike.
> > > 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.
>
> This was posed as a thought experiment in language design.
And, for reasons mentioned below, an interesting one at that. DEFINE
and the top-level environment have always been problematic, but no-one
*really* wants to only allow LETREC and function application at
top-level, even if it is semantically cleaner FWIW, Stalin actually
works that way: it internally wraps the user program in a giant LETREC
(or so I remember) with all of the top-level bindings to RnRS
procedures.
> The most obvious counter to this line of argument is that the
> defines are meta-operations (extending environments at compile time),
> so bar would have a local binding in all instances.
Not entirely sure what you mean by 'DEFINEs are meta-operations', but
it is patently true that DEFINE is the only binding form in Scheme
that does not have a clearly delimited extent. The analogy to LETREC
was introduced to try and have it make some kind of sense. But it's
also worth noting that the restriction that internal DEFINE only
appear at the head of a LAMBDA or LETREC (BEGIN being equivalent to
niladic LAMBDA) is pretty arbitrary and smells of implementation
details - and I think Chicken removes that restriction and allows
internal define anywhere within straight-line code.
The real question is whether all identifiers (not just the ones
explicitly DEFINEd) are bound to bottom or if it really is a syntax
error for an identifier to not have been defined. Practically, this
decision shows up in whether SET! at top-level is required to raise an
error. Curiously enough, the answers to this question closely
correlate with interpreted vs compiled preferences :)
For myself, internal DEFINE is a syntactic sugar I can live without,
although I do occasionally use it. Since we're talking in the context
of ERR5RS I think that keeping it as close to R5RS as possible is
desirable. But it might be fun to explore the idea more in the
Platonic Ideal context.
> While I have been writing this out, the following post on
> comp.lang.scheme occurred:
> http://groups.google.com/group/comp.lang.scheme/browse_thread/thread/cf6204666533c68c/#
> , showing that this notion of define has some pragmatic appeal.
Yes. And it would also make my FUNCTOR module system's macros rather
more elegant as well, but that's just not R5RS.
david rush
--
Once you label me, you negate me
- Soren Kierkegaard
More information about the Err5rs
mailing list