Common Lisp中我注意到,我可以這樣寫:我可以參考defstruct中的其他插槽嗎?
(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
有沒有辦法做到這一點?
啊,這好像是我所希望的......謝謝! – casper 2009-02-12 22:39:11