Common lisp 使用&;允许使用公共lisp中的其他键

Common lisp 使用&;允许使用公共lisp中的其他键,common-lisp,Common Lisp,我想使用最通用的函数,并决定使用键作为参数。 我想使用允许其他键,因为我想使用任何键的功能 让我告诉你: (defun myfunc (a &rest rest &key b &allow-other-keys) ;; Print A (format t "A = ~a~%" a) ;; Print B if defined (when b (format t "B = ~a~%" b)) ;; Here ... I want to pri

我想使用最通用的函数,并决定使用键作为参数。 我想使用
允许其他键
,因为我想使用任何键的功能

让我告诉你:

(defun myfunc (a &rest rest &key b &allow-other-keys)
  ;; Print A
  (format t "A = ~a~%" a)

  ;; Print B if defined
  (when b
    (format t "B = ~a~%" b))

  ;; Here ... I want to print C or D or any other keys
  ;; ?? 
)

(myfunc "Value of A")
(myfunc "Value of A" :b "Value of B")
(myfunc "Value of A" :b "Value of B" :c "Value of C" :d "Value of D")
我知道剩余的参数是
rest
,但它有一个数组。它不会绑定值
c
d
,甚至不会像创建关联列表一样构建它们(即执行类似
(cdr(assoc'c rest))

你有什么线索或解决办法吗?或者我走错了方向

提前感谢

什么时候&REST是数组?标准上说是列表。对于关键字参数,这是一个属性列表。请参见
getf
,以访问属性列表的元素

您还可以使用
DESTRUCTURING-BIND
访问该属性列表的内容:

CL-USER 15 > (defun foo (a &rest args &key b &allow-other-keys)
               (destructuring-bind (&key (c nil c-p) ; var default present?
                                         (d t   d-p)
                                         (e 42  e-p)
                                    &allow-other-keys)
                   args
                 (list (list :c c c-p)
                       (list :d d d-p)
                       (list :e e e-p))))
FOO

; c-p, d-p, e-p  show whether the argument was actually present
; otherwise the default value will be used

CL-USER 16 > (foo 10 :b 20 :d 30)
((:C NIL NIL) (:D 30 T) (:E 42 NIL))

但是在参数列表中也可以这样做…

很抱歉类型混淆。是的,这是一份清单,你完全正确。在我的例子中,我将查看
getf
。谢谢你的回答。我仍然很困惑,因为
rest
有这个值:
(C值的cd值的D)
但是
(getf rest'C)
或者
(getf rest'C)
给我
NIL
好的。。。我的错<代码>:c。我真傻。谢谢,雷纳