Saturday, February 7, 2009

lisp question

Does anyone know if you can reference earlier slots when using the defstruct macro? For instance:

CL-USER> (defstruct thing a b c)

THING
CL-USER> (setq q (make-thing :a 1 :b 2 :c (+ a b)))
; Evaluation aborted (didn't work)
CL-USER> (setq q (make-thing :a 1 :b 2 :c (+ :a :b)))
; Evaluation aborted (didn't work)

So what I would like to do is reference :a and :b when defining :c. Google searches haven't really helped out.

1 comment:

  1. Try this:

    CL-USER> (setq x (make-thing :a 2 :b 3 :c (+ (thing-a x) (thing-b x))))

    #S(THING :A 2 :B 3 :C 5)

    I guess you cannot use :a or :b as they are just the keys binding positional parameters and do not have a value associated with them.

    ReplyDelete

Note: Only a member of this blog may post a comment.