Page 1 of 1

Specializing Methods on Keywords

Posted: Sun Jun 21, 2009 8:40 am
by Harnon
I don't necessarily need it, but it would simplify things if i could specialize a method parameter on a keywords in general (not just one type), distinguishing them from
regular symbols. I've looked on google, but couldn't find anything.
When i try
(defmethod test ((a keyword))) or (defmethod test ((a key))) it gives the error keyword and key is not a class.
Thx! :D

Re: Specializing Methods on Keywords

Posted: Sun Jun 21, 2009 8:54 am
by ramarren
While KEYWORD is a type, it is not a class, and so you cannot specialize methods on them. All types which have corresponding systems classes are listed in the Hyperspec, and unfortunately keywords are not one of them. It seems to be just a flaw in the standard, since keywords form a subset of symbols, so there would be no ordering issues.

It seems the only thing to do is do a manual dispatch in the SYMBOL-specialized method using ETYPECASE or similar.

Re: Specializing Methods on Keywords

Posted: Sun Jun 21, 2009 9:08 am
by Harnon
Oh well. Thx!

Re: Specializing Methods on Keywords

Posted: Tue Jun 23, 2009 9:37 am
by findinglisp
You can do EQL specialization on a parameter. For instance:

Code: Select all

(defmethod foo (p1 (p2 (eql :bar))
    ...)

(defmethod foo (p1 (p2 (eql :quux))
    ...)