Folks,
Please take a look at
http://www.franz.com/support/documentation/7.0/ansicl/dictentr/with-slo.htm
1. I didn't know you could (defmethod (setf thing-x) :before (new-x
(thing thing)) ... Is this portable? Seems an amazing discovery to me.
2. What is the point of (thing-x thing) in this method? Why not just
thing-x?
Thanks in advance, Joel
On 12 Feb 2005 03:54:20 -0800, "Joel Reymont" <······@gmail.com> wrote:
> 1. I didn't know you could (defmethod (setf thing-x) :before (new-x
> (thing thing)) ... Is this portable? Seems an amazing discovery to
> me.
Yes, it is.
> 2. What is the point of (thing-x thing) in this method? Why not just
> thing-x?
Because you can have several different methods specializing on
different types.
* (defparameter *foo* (make-hash-table))
*FOO*
* (defmethod foo (key)
(gethash key *foo*))
; Compiling LAMBDA (PCL::.PV-CELL. PCL::.NEXT-METHOD-CALL. KEY):
; Compiling Top-Level Form:
#<STANDARD-METHOD FOO (T) {58353085}>
* (defmethod (setf foo) (new-value key)
(setf (gethash key *foo*) new-value))
; Compiling LAMBDA (PCL::.PV-CELL. PCL::.NEXT-METHOD-CALL. NEW-VALUE KEY):
; Compiling Top-Level Form:
#<STANDARD-METHOD (SETF FOO) (T T) {582EAB5D}>
* (defmethod (setf foo) :before (new-value (key symbol))
(format t "About to use symbol ~S as a key~%" key))
; Compiling LAMBDA (PCL::.PV-CELL. PCL::.NEXT-METHOD-CALL. NEW-VALUE KEY):
; Compiling Top-Level Form:
#<STANDARD-METHOD (SETF FOO) :BEFORE (T SYMBOL) {583BF235}>
* (setf (foo 1) 'bar)
BAR
* (foo 1)
BAR
T
* (setf (foo 'baz) 'quux)
About to use symbol BAZ as a key
QUUX
If you just write NEW-VALUE instead of (NEW-VALUE <something>) it's
equivalent to (NEW-VALUE T) where T is the union of all types.
Get a copy of Keene's classic book[1] if you haven't read it already.
Maybe there are more pleasant surprises waiting for you... :)
Cheers,
Edi.
[1] Sonya Keene: Object-oriented Programming in Common Lisp
A Programmer's Guide to CLOS.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")