在Common Lisp中有没有一种方法可以创建一个泛型函数,其中专用于参数的参数是关键字参数?
例如,而不是这个:
CL-USER> (defgeneric tst (a)) #<STANDARD-GENERIC-FUNCTION TST (0)> CL-USER> (defmethod tst ((a list)) (print a)) #<STANDARD-METHOD TST (LIST) {1004ECC903}>..在参数'a'上指定。 我想要有以下几点:
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}>显然,这与设置关键字参数的默认值的语法冲突,所以我有点卡住了。 在实际的代码中,这个问题与我选择了不同的参数布局有关,所以这不是问题(并且引导起来有点整洁!)但是如果我再遇到这个问题,我想我最好问专家!
欢呼一切
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
最满意答案
不,这不是Common Lisp提供的。
No, that's not provided by Common Lisp.
更多推荐
发布评论