Is there a way in Common Lisp to create a generic function
where the argument to specialize on is a keyword argument?
For example rather than this:
CL-USER> (defgeneric tst (a))
#<STANDARD-GENERIC-FUNCTION TST (0)>
CL-USER> (defmethod tst ((a list))
(print a))
#<STANDARD-METHOD TST (LIST) {1004ECC903}>
..which specifies on the argument ‘a’.
I’d like to have the following:
CL-USER> (defgeneric tst (&key a))
#<STANDARD-GENERIC-FUNCTION TST (0)>
CL-USER> (defmethod tst (&key (a list))
(print a))
#<STANDARD-METHOD TST (LIST) {1004ECC903}>
Obviously this clashes with the syntax for setting the
default values of keyword arguments so I’m a tad stuck. In the actual code this problem relates to I chose a different argument layout so this wasn’t an issue (and was a bit tidier to boot!) but in case I run into this again I thought I best ask the experts!
Cheers all
No, that’s not provided by Common Lisp.