Student
Student

Reputation: 719

Common Lisp processing Structure slots sequentially

Is there a work-around for structure body slot bindings to be processed in sequence as in LET* so that previous slot assignments are visible to later ones?

For instance in the following i want c to be visible for d.

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

How could i get this effect?

Upvotes: 2

Views: 124

Answers (1)

Svante
Svante

Reputation: 51501

You already use a boa constructor. You can use its boa lambda list to do things in order:

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

Upvotes: 6

Related Questions