【发布时间】:2009-02-08 14:33:25
【问题描述】:
在普通的 lisp 中,我注意到我可以这样写:
(defun foo (&key (a 1) (b 2) (c (+ a b))) (print (+ a b c)))
当我调用(foo) 时,会打印6。所以参数c 可以引用为a 和b 设置的值。但我似乎找不到与defstruct 做类似事情的方法。比如:
CL-USER> (defstruct thing a b c)
THING
CL-USER> (setq q (make-thing :a 1 :b 2 :c (+ a b)))
; Evaluation aborted
CL-USER> (setq q (make-thing :a 1 :b 2 :c (+ :a :b)))
; Evaluation aborted
有没有办法做到这一点?
【问题讨论】:
标签: common-lisp