[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

meaning of local define



My thoughts about local DEFINE and RECless DEFINE:

1) I think that local DEFINEs should be EXACTLY equivalent to LETREC.
I also think that the standard should ONLY support LAMBDA expressions
in LETREC, thus

  (define (foo x)			; (1)
    (define bar (1+ x))
    (define baz (* bar bar))
    (/ baz 6))

would be unspecified (might be an error in some implementations), and
so would

(letrec ((a (cons 3 (lambda () a))))	; (2)
  a)

and similar things.

Individual implementations may extend the semantics of LETREC and
local DEFINE, but it is up to them to give a consistent semantics.

I REALLY dislike expressions of type (2) above because they are very
misleading, and dislike expressions of type (1) almost as much.

Note that I am a partisan of local DEFINE.  I also think (from
previous discussions) that most people at MIT would accept
this.  We've agreed on it before but never enforced it on MIT Scheme.

2) I think that DEFINE should not have an implicit NAMED-LAMBDA.  I
think that naive users will get confused either way (in equal
numbers), and thus the decision should be left to us.  


At MIT, DEFINE behaves differently on the Scheme system on which S&ICP
is run (we call this the student system) from the one which we use
(which we call the development system).  The student system always
uses the semantics implied by the interpreter in section 4.1 of S&ICP
(as opposed to the LETREC definition).  We call this semantics
"incremental" DEFINE, rather than "local" or "internal" DEFINE.  I
have not seen a single person have any problems when transferring from
the student system to the development system (most of our hackers,
including myself, transferred at one point from one to the other), so
this incompatibility is not very important in practice.

Thus my suggestion to CPH, JMILLER, and other people at MIT concerned
about naive users, is that we keep these differences (implicit
NAMED-LAMBDA vs. LAMBDA, incremental vs. local DEFINE) in semantics
between both systems, but the standard should be cleaner.

Note: for the difference between both semantics for DEFINE, read
section 5.2.5 of S&ICP.  In particular, read exercise 5.27.  The
student system at MIT would return 16, the development system would
signal an error.  Again, I do not remember seeing users run into this
difference when transferring from one system to the other, because
good style dictates that all internal definitions be used for defining
procedures only, and it is this restriction that I would like to place
on the standard.