[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: parameter specializer (eql object) -- I'm confused
- To: pshannon@iapetus.cv.nrao.edu (Paul Shannon), info-mcl
- Subject: Re: parameter specializer (eql object) -- I'm confused
- From: straz@cambridge.apple.com (Steve Strassmann)
- Date: Mon, 20 Jun 1994 22:02:44 -0400
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))