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!
Specializing Methods on Keywords
Re: Specializing Methods on Keywords
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.
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
Oh well. Thx!
-
- Posts: 447
- Joined: Sat Jun 28, 2008 7:49 am
- Location: Austin, TX
- Contact:
Re: Specializing Methods on Keywords
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))
...)
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/