通用Lisp处理结构插槽顺序

时间:2019-12-08 13:31:44

标签: struct common-lisp

是否有一种变通方法,可以像LET*中那样按顺序处理结构主体插槽绑定,以便以后的插槽可见先前的插槽分配?

例如,在下面的示例中,我希望c可见d

(defstruct (my-struct (:constructor cons-struct (a b)))
  (c (* a b))
  (d c))

我怎么能得到这种效果?

1 个答案:

答案 0 :(得分:6)

您已经使用了boa constructor。您可以使用其boa lambda list按顺序执行操作:

(defstruct (my-struct (:constructor cons-struct (a b
                                                 &aux
                                                  (c (* a b))
                                                  (d c))))
  c
  d)