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

``Update functions'' in Scheme.



> Following the discussion on assignments in Scheme, and how to have them
> performed in subroutines, the following question strikes my mind:
> 
> *** Why didn't the designers of Scheme include locations (~anonymous variables)
> as first-class values in the language? ***

One possible reason (for T at any rate) is that setting is more general than
simply putting a value into a location.  For a slightly contrived example,
let's take an abstract data type of complex numbers in which all the
coordinates are settable:

(LSET C (MAKE-COMPLEX-FROM-RECTANGULAR 0.3 10.8))
      
(SET (COMPLEX-THETA C) (/ PI 2))

(SET (COMPLEX-X C) 0.0)

Now, the X, Y, R, and THETA attributes of a complex number aren't all going
to be stored in variables.  Even if they were it wouldn't help: setting (X C)
will usually change the values that (R C) and (THETA C) should have.  

In general, the operation of stuffing a value into a location is
inappropriate for abstract data types: even when it works, it is too
implementation-dependent.  There's no choice but to use mutator procedures.
Since we have to use them anyways, why not be clean and not bother with
locations?  Do you really want to imitate BLISS and require explicit
dereferencing for every mutable variable?

-- Bard the (LAMBDA (X) GARGOYLE)

(P.S.: That's a good enough argument for theoreticians like me.  T actually
has locatives.  I don't know how they work.)