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

Instance variables



The way to think of it is that the defmethod form wraps the method code with
something that "binds" the instance variables.  If you bind something of the
same name, it shadows the instance-variable binding, as always.  I've probably
said this too many times already, but it is my strong opinion and belief that
instance variables are naturally lexical (accessible only inside methods).  If
so, I see no reason why they can't act just like Common Lisp lexical variables
and get closed over, etc.  The result is very Common Lispy.

An illustration of closure:

(Defflavor my-flavor (a b) () :settable-instance-variables)
(defmethod (my-flavor :closure) ()
  #'(lambda () a))
(funcall (send (make-instance 'my-flavor) :closure)) --> 3.

If this is not the case, the semantics of that reference have changed, probably
from being an instance variable to being something else.  This is gross and
confusing. 

-- Steve