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

Side effecting constants inside functions

    Date: Tue, 20 Aug 85 02:52:22 EDT
    From: Tim McNerney <TIM@MIT-MC.ARPA>

    In CLtL, I can't find any mention of the issue of side effecting
    internal constants.  In Maclisp, NIL, Zetalisp, and presumably most
    Common Lisp implementations, the function:

      (defun withdraw (amount)
	(let ((balance '(1000)))
	  (decf (first balance) amount)))

    acts much like a lexical closure with a local state variable.
    Thus, (withdraw 100) => 900, then (withdraw 100) => 800, etc.  This 
    behaviour has always bothered me.  Is this rather questionable style 
    condoned by Common Lisp?

We consider the fact that this "works" in Symbolics-Lisp (nee Zetalisp)
a deficiency which we intend to remedy now that our VM system can handle
read-only areas.  I would certainly hope that no one would depend on
this working.  (Faint hope, from talking to people at IJCAI.)