On Wed, Dec 29, 2010 at 9:26 PM, Alex Osborne <a...@meshy.org> wrote:
> Todd <t.greenwoodg...@gmail.com> writes:
>
>> 3. alter ref2 to have a reference (pointer) to ref1
>>
>> user=> (dosync (ref-set aref2 {:a aref1}))
>> {:a #<r...@98adae2: {:a #<r...@7b283052: {:a #<r...@98adae2: {:a
>> #<r...@7b283052: {:a #<r...@98adae2: {:a #<r...@7b283052: {:a
>> #<r...@98adae2: {:a #<r...@7b283052: {:a #<r...@98adae2: {:a
>> #<r...@7b283052: {:a #<r...@98adae2: {:a #<r...@7b283052: {:a
>>
>> <SNIP...>
>>
>> {:java.lang.StackOverflowError
>>
>> <SNIP...>
>>
>> 4. So, I've got a stack overflow... What's the proper way to deal with
>> this? Are circular references like this not allowed?
>
> Circular references are allowed, the problem is with the repl trying to
> print them.  You can set the *print-level* var to put a limit on how
> deep the printer will go.

Concur. But one more thing: I find it a bit icky to have refs inside
other refs. I'd prefer something more like

{:a (ref (some-object-mentioning :b))
 :b (ref (some-object-mentioning :a))}

i.e. the values of some map entries reference the keys of some other
map entries, rather than anything being truly circular. (For one
thing, doing so always, perfectly avoids problems with debug and repl
prints overflowing the stack due to circular references!)

-- 
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