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

Generating an implicit WITH-SLOTS a la Flavors



I need a form that generates a CLOS method definition but encloses the
body in a scope in which all slots of the first argument to the method
are referenceable without qualification, as Flavors does.  (Forgive us -
this is a transitional measure only.)  The difficulty is that these
methods may occur in the same file as the class definition itself, so
the class is not finalized - nor can it be, since STANDARD-OBJECT is a
mere FORWARD-REFERENCED-CLASS at this point (compile time).  Hence, the
complete slot list is not yet available via CLOS:CLASS-SLOTS.  The best
I've come up with is along the lines of

(defun 1slot-names 0(class)
  (unless (typep class 'clos:forward-referenced-class)
    (let ((direct-slot-names (mapcar #'clos:slot-definition-name (clos:class-direct-slots class))))
      (delete-duplicates (nconc direct-slot-names
				(mapcan #'slot-names (clos:class-direct-superclasses class))
				))
      )
    )
  )

(defmacro 1define-method 0((method-name class-name) arglist &body forms &environment env)
  `(defmethod ,method-name ((self ,class-name) ,@arglist)
     (with-slots ,(slot-names (find-class class-name t env)) self
       ,@forms
       )
     )
  )

Does anyone have a better solution?


	Lawrence G. Mayka
	AT&T Bell Laboratories
	lgm@iexist.att.com

Standard disclaimer.