Does CLOS have an eql specialization dispatch on strings?

Posted by mhb on Stack Overflow See other posts from Stack Overflow or by mhb
Published on 2010-03-29T20:42:43Z Indexed on 2010/03/29 21:03 UTC
Read the original article Hit count: 258

Filed under:

Examples of what you can do.

(defmethod some-fn ((num real)) (print "an integer"))
(defmethod some-fn ((num real)) (print "a real"))
(defmethod some-fn ((num (eql 0))) (print "zero"))

(some-fn 19323923198319)
"an integer"
(some-fn 19323923198319.3)
"a real"
(some-fn 0)
"zero" 

It also works with a general 'string type.

(defmethod some-fn ((num string)) (print "a string"))
(some-fn "asrt")
"a string"

Not with a specific string, however

(defmethod some-fn ((num (eql "A")) (print "a specifict string")))     
=> doesn't compile

I imagine it doesn't work because eql does not work on strings in the way that would be necessary for it to work.

(eql "a" "a") => nil

Is there a way to do it?

© Stack Overflow or respective owner

Related posts about common-lisp