On 07/06/2012 09:54 PM, Mark Engelberg wrote:
> You basically have two choices.
>
> Choice 1, give names to each of your nodes, and link names to names.
> (def cycle {:a {:value 2, :link :b}, :b {:value 3, :link :a}}
>
> Choice 2, use one of Clojure's reference types
> (def a (ref {:value 2}))
> (def b (ref {:value 3}))
> (dosync (alter a assoc :link b) (alter b assoc :link a))
I think promises are a great fit for this use case, as the result is
immutable.
;; Don't try to print all of the infinite data structure.
(set! *print-level* 20)
(let [a (promise)
b (promise)]
(deliver a {:b b})
(deliver b {:a a})
(pprint @a))
; {:b
; #<Promise@c69d7ee:
; {:a
; #<Promise@78df509f:
; {:b
; #<Promise@c69d7ee:
; {:a
; #<Promise@78df509f:
; {:b
; #<Promise@c69d7ee:
; {:a #<Promise@78df509f: {:b #}>}>}>}>}>}>}
;= nil
--
Timo
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en