One way you could do it is by building up the members incrementally
via 'let':

(defstruct tz :a :b :c)

(def tz1 (let [a 1
               b 2
               c (+ a b)]
           (struct tz a b c)))

On Nov 13, 7:31 am, garf <gary.overg...@gmail.com> wrote:
> If I have a struct whose creation will require some function calls
> that references some of its members, I am unsure how to go about it in
> a clean way.  For example:
> (defstruct tz :a :b :c)
>
> (def tz1   1  2  (+ (:a tz1) (:b tz1))
>
> will not work, but reflects the problem.   Ideally at the end of this
> I could do (:c tz1) and get 3 back.  Any suggestions?   Originally I
> had used assocs, but that runs into the immutability problem, for
> example
>
> (defstruct tz :a :b)
> (def tz1  1 2)
> (assoc tz1 :c  (+ (:a tz1) (:b tz1))
>
> does not actually update tz1
>
> Advice for better approaches?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to