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

Re: Correction



    From: Scott McKay <SWM@SAPSUCKER.SCRC.Symbolics.COM>
    Subject: Correction

        Date: 23 Jul 1987 20:38-EDT
        From: VERACSD@A.ISI.EDU

    	 (I might add that Symbolics does not allow lexical
        bindings around defmethods (not sure about TI); I hope they
        will consider it.)

    Isn't this what instance variables are for?  In CLOS, methods
    get to choose what "slots" (CLOSpeak for "instance variable") they
    are allowed to access, so can get the "own variable" behavior you
    want that way.

No, this kind of use of lexical variables is not at all the same as
slots (instance variables).  Slots are a piece of storage which is
associated with an object (in the case of class variables it can be more
than one object).  Effectively that means that with respect to the body
of the method slots are dynamic variables.  Needless to say, lexical
variables around a defmethod aren't dynamic variables.  Here is what I
think of as a prototypical example of methods using both a slot and a
lexical variable.

(defclass plist-mixin ()
    ((plist :initform ()
            :accessor plist)))

(let ((mark (list "mark")))

  (defmethod mark  ((x plist-mixin))
    (setf (getf (plist x) mark) t))

  (defmethod markp ((x plist-mixin))
    (getf (plist x) mark))

  )