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

WITH-SLOTS, "virtual" slots, and the meta-object protocol

Start with the standard x/y v rho/theta example:

(defclass position () (x y))
(defmethod rho ((p position)) ...)
(defmethod theta ((p position)) ...)
(defmethod-setf rho ((p position)) (value) ...)
(defmethod-setf theta ((p position)) (value) ...)

What if a user of the POSITION class writes the following method:

(defmethod zoom ((p position) n)
	(with-slots (p)
		(setf rho (* n rho))))

How is this going to work?  Presumably the WITH-SLOTS macro consults the
class to find out what vars should be treated as slot references, but
the notion that RHO and THETA are slots has not been made explicit.  How
does the writer of the POSITION class tell the class about these
"virtual" slots?  Perhaps there should be macros that let you write

(defaccessor rho ((p position)) ...)
(defaccessor-setf rho ((p position)) ...)

or maybe a new method-qualifier so you could write

(defmethod rho :accessor ((p position)) ...)
(defmethod-setf rho :accessor ((p position)) ...)

I guess there could also be another class-option added to DEFCLASS, but
even if there were, something like these macros would be needed.

----- smL