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

meaning of local define



    ...

    (define (quux x) (* x x))

    (define (foo y)
      (define bar (quux y))
      (define (quux x) (* x x x))
      (quux y))

    ...

    3) It is an error because the definitions occur all in parallel but
    the values are assigned sequentially, and thus QUUX is bound but not
    assigned on first use.  This is what MIT Scheme does currently (and
    used to do for top level).  

Multilisp has adopted a position which is a superset of this.  I'm not
terribly strongly attached to it, but I think it is pragmatic given that
none of the alternatives is wonderfully appealing.  DEFINEs are allowed
to appear anywhere at the "top level" (which includes possibly being
nested inside BEGINs) of a "variable-binding form" (which means lambda
bodies, let bodies, and the like).  They may be interspersed with other
non-DEFINE forms -- in other words, they don't have to all be collected
at the beginning of a body.  The meaning of DEFINEs is specified by the
following (operationally stated) rule:  all variables named in DEFINEs
at the top level of a particular body are bound to unassigned values on
entry to that body, and the DEFINEs themselves are changed to SET!s and
left where they are in the body.  This implies a little more work for a
compiler or interpreter than the current RRRS position, but I don't
think it's really much uglier since even the current RRRS stance allows
arbitrary computations to occur in calculating the values to be bound to
some DEFINEd variables without waiting for all the variables' values to
have been assigned.

I think we should decide if we want DEFINE merely for compatibility with
S&ICP (in which case we should scan the book & find out the minimal
semantically appealing definition that will work for all the examples
given) or whether we would put DEFINE in the Scheme standard even if
S&ICP didn't mention it (in which case a debate about more "powerful"
versions is appropriate).  I tend toward a theory that essential Scheme
should only include the minimum required for S&ICP to work.  But I'll
confess I still find it a muddle to know how to proceed from that
decision.