[r6rs-discuss] [Formal] Disallow redefinitions macros/variables

From: William D Clinger <will>
Date: Tue Mar 27 20:50:33 2007

I am posting this as an individual member of the Scheme
community. I am not speaking for the R6RS editors, and
this message should not be confused with the editors'
eventual formal response.

Andre van Tonder correctly observed that the change
to letrec* semantics for internal definitions will
make optimization more difficult. With the letrec*
semantics, Scheme programmers would just have to
learn that internal definitions are assignments in
disguise, and those who wish to avoid unnecessarily
inefficient code would learn to follow these simple
rules:

    1. The right hand side of every internal
        definition should be either a lambda
        expression, a variable, or a constant.

    2. If the right hand sides of some internal
        definitions really need to be something
        other than a lambda expression, variable,
        or constant, then those particular internal
        definitions should come after all the others.

With the letrec semantics of R5RS and previous
reports, programmers didn't have to follow those
rules because compilers were allowed to reorder
internal definitions.

Andre van Tonder wrote:
> In any case, implementing such a "should" should require a single extra
> runtime comparison per DEFINE if we translate the latter to something like
> SET!-IF-UNDEFINED with the obvious semantics.

As often happens, there are at least three different
obvious semantics. One is to evaluate the right
hand side of the definition unconditionally, but
to avoid the assignment if the variable has already
been assigned a value. Another is to evaluate
the right hand side only if the variable does not
yet have a value. A third is to evaluate the right
hand side only if the variable does not yet have a
value, and *also* to avoid the assignment if the
variable has already been assigned a value.

(Proving that the third semantics is distinct from
the other two is left as an exercise for readers
who wish to understand a dark corner of Scheme.)

Will
Received on Tue Mar 27 2007 - 20:24:55 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC