3 ms·
So far there's only one solution: "this can be done (for common lisp) by handling undefined-function condition and invoking appropriate restart (which is unfort
by mahmud 17y ago
So far there's only one solution: "this can be done (for common lisp) by handling undefined-function condition and invoking appropriate restart (which is unfortunately implementation-specific)."
Before you go far and wide on speculation alone, you might stop and reread what has been posted so far, again. Both me and lnostdal submitted working CL solutions.
Example of a situation this feature might be useful: "I have this object with lots of properties which I don't necessarily know what they are. How do I define getter/setter methods on them?"
;; if you know the slot names
(slot-value object 'slot-name) ==> value
(setf (slot-value object 'slot-name) new-value)
;; if you don't.
;; let's define a class hierarchy first
CL-USER> (defclass foo () ((a) (b)))
#<STANDARD-CLASS FOO>
CL-USER> (defclass bar (foo) ((c) (d)))
#<STANDARD-CLASS BAR>
CL-USER> (defclass baz (bar) ((e) (f)))
#<STANDARD-CLASS BAZ>
;; use COMPUTE-SLOTS to get the class's slots
CL-USER> (closer-mop:compute-slots (find-class 'baz))
(#<STANDARD-EFFECTIVE-SLOT-DEFINITION A #x1A0F62C5>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION B #x1A0F6305>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION C #x1A0F6345>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION D #x1A0F6385>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION E #x1A0F63C5>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION F #x1A0F6405>)
;; if you have an object and not a class, do the same
CL-USER> (closer-mop:compute-slots (class-of (make-instance 'baz)))
(#<STANDARD-EFFECTIVE-SLOT-DEFINITION A #x1A1202A1>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION B #x1A1202E1>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION C #x1A120321>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION D #x1A120361>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION E #x1A1203A1>
#<STANDARD-EFFECTIVE-SLOT-DEFINITION F #x1A1203E1>)