[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
meaning of local define
Date: Thursday, 27 March 1986 15:40-EST
From: Jonathan A Rees <JAR at MC.LCS.MIT.EDU>
This can make a difference when a user tries to figure out whether
expressions like the following will return a well-defined result:
(define (foo x)
(define bar (1+ x))
(define baz (* bar bar))
(/ baz 6))
According to the documentation of DEFINE, this is equivalent to
(define (foo x)
(letrec ((bar (1+ x))
(baz (* bar bar)))
(/ baz 6)))
I'm not a big fan of local define's, but I think that if they are
implemented, they should have right-to-left semantics. I believe
local-DEFINE partisans will agree with this.
I (sort of) like local-DEFINE. If I understand correctly, you would
like to have them be evaluated sequentially because each appears,
syntactically, to be a side-effect. I feel funny about this, because
the example above is precisely the kind of thing that constantly
screws up beginning users in 6.001.
I'm used to thinking of local-DEFINE as a syntax for LETREC (which
takes less horizontal space!), and not having any dependence on order
of evaluation. And in fact I consider that very, very bad style.
The example above should be written using LET.
In fact, the only useful values in local-DEFINE or LETREC are
procedure definitions and delayed evaluations, because nothing else
can need the mutual recursion -- every other kind of expression can
always be written using LET.
Anyway, to get to the point: as I recall, local-DEFINE was included in
the standard only because of S&ICP. I would favor leaving the current
description of its semantics, perhaps with a prominent note to that
effect, and recommending LETREC for new code.
I should probably learn to use LETREC instead, but I fear I'm too
attached to DEFINE by now.