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

Re: parameter specializer (eql object) -- I'm confused



At  1:12 AM 6/21/94 +0000, Paul Shannon wrote:
 >I would like to be able to specialize a method on the value of
 >an object, like this:
 >
 >    (defmethod dispatch ((eql "Save"))
 >       ...)
 >
 >I can't get this to work under Macintosh Common Lisp (2.0.1)
 >Specifically:
 >
 >(defmethod dispatch-callback ((eql "Apple") (eql "Save"))
 >  (format t "dispatch-callback:  apple, save~%"))

Well, for one thing, you need to provide variable names for your two
arguments:

(defmethod dispatch-callback ((menu (eql "Apple")) (item (eql "Save")))
   (format t "~%dispatch-callback:  ~A, ~A" menu item))

This will compile, but I'm afraid this doesn't work properly either because
two similar-looking strings are not necessarily EQL to each other, because
they are not, in fact, the SAME string. They are, however, EQUAL.

? (eql "this" "this")
nil
? (equal "this" "this")
t

Try using symbols or keywords instead:

(defmethod dispatch-callback ((menu (eql :Apple)) (item (eql :Save)))
   (format t "~%dispatch-callback:  ~A, ~A" menu item))