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

Re: Function cells



   As an aside to the main discussion, I do not condone the use of both
the function and the value cell as a programming style, I am also doubtful
about Tim's appellation of this as a feature.

   I should also remark that there are some 'real' LISPs that only provide
one location for keeping a value associated with an id (ie no function cell),
in particular Cambridge LISP.

   I would vote with Tim to remove this dichotomy which is being continued in
Common LISP, for reasons which are given in more detail below. However I 
strongly suspect that the main reason for its retention in CL is not for
aesthetic but political motives - how else is MACSYMA going to run under CL,
the coding style therein uses this  'feature' quite a lot, and rewriting
all the affected parts is not an overnight job.

   I maintain that a function IS a value, and the distinction between value
and function is erroneous. Although no-one would seriously regard LISP as a
faithful implementation of the semantics of lambda calculus, it is not
unreasonable to pay lip service to its (our??) heritage.

   With respect to the question of clarity: there is a problem with the
handling of anonymous functions (as in say the MAP functions), and in the
case of high order functions. Although this example may seem somewhat
contrived, it is relevant.

   R-Sum and I-sum define functions to do a curried summation (I provide
both for a little variety):

(De R-Sum (a0)
  (Function
    (Lambda (ai)
      (Cond ((Zerop ai) a0) (t (R-Sum (Plus a0 ai)))))))

alternatively:

(De I-Sum (a0)
  (Prog (fn)
    (Return
      (SetQ fn
        (Function 
          (Lambda (ai)
            (Cond ((Zerop ai) a0) (t (SetQ a0 (Plus a0 ai))))
            fn))))))

    now using these in a single cell system gives rise to the following
expression:

      (((((I-sum 1) 2) 3) 4) 0)

    if FUNCALL must be used this becomes:

      (FunCall (FunCall (FunCall (FunCall (I-sum 1) 2) 3) 4) 0)


    In addition to being a matter of style/personal taste, it is a
question of consistency (as Peter Deutsch remarked), each element of
a form is treated the same way - even assuming the first element is
evaluated repeatedly until an object which can be applied is found, since
that is simply a recursion in eval without passing the rest of the form
downwards.

--Julian Padget.
-------