infinite loop print out of cyclic structure at repl

138 views
Skip to first unread message

Raoul Duke

unread,
Jan 18, 2010, 4:22:47 PM1/18/10
to clo...@googlegroups.com
hi,

hmmm, i wish there were a way (or that it was the default) to tell the
repl to not continue to loop for ever over things it has already
"printed" out when i eval something that is a cyclic thing. anybody
have a patch, or thought on this?

thanks!

Mark Hamstra

unread,
Jan 18, 2010, 4:38:46 PM1/18/10
to Clojure
See *print-length* and *print-level* in the core API.

Chouser

unread,
Jan 18, 2010, 5:21:52 PM1/18/10
to clo...@googlegroups.com
> On Jan 18, 4:22 pm, Raoul Duke <rao...@gmail.com> wrote:
>> hi,
>>
>> hmmm, i wish there were a way (or that it was the default) to tell the
>> repl to not continue to loop for ever over things it has already
>> "printed" out when i eval something that is a cyclic thing. anybody
>> have a patch, or thought on this?

On Mon, Jan 18, 2010 at 4:38 PM, Mark Hamstra <markh...@gmail.com> wrote:
> See *print-length* and *print-level* in the core API.

Or if you want unlimited depth, but want to avoid printing the
value of any reference object more than once, you can try this
little thing I hacked together a while ago:

http://paste.lisp.org/display/83647

Note that it has to keep a reference to every IDeref object it
sees while it's printing, in order to detect duplicates.

--Chouser
http://joyofclojure.com/

Raoul Duke

unread,
Jan 18, 2010, 5:43:21 PM1/18/10
to clo...@googlegroups.com
> Mark
> Chouser

thanks, all.

Patrik Sundberg

unread,
Oct 1, 2013, 12:44:44 PM10/1/13
to clo...@googlegroups.com, cho...@n01se.net
This paste seems gone - anyone has it available?

I seem to get bitten by this kind of thing in emacs using nrepl and it pretty printing something and it gets into an infinite loop locking up my emacs session completely. Running the same from command line i can see same behavior (seems related to protocols in my case, but haven't spent much time on it(). Either way I'd love to work out a way to avoid the cycles and this paste sounds good.

Chouser

unread,
Oct 1, 2013, 2:57:56 PM10/1/13
to clo...@googlegroups.com
Bah, mutable state! To be cursed in all its forms!

Here is the same content as was at that paste.lisp.org link. I haven't
tested it with recent versions of Clojure or anything:

https://gist.github.com/Chouser/6783292

--Chouser
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
--Chouser

dieter.v...@gmail.com

unread,
Jan 1, 2022, 4:25:28 AM1/1/22
to Clojure
Hello,

I'm trying the proposed solution ('want unlimited depth, but want to avoid printing the
value of any reference object more than once'). But running into issues:
- clojure.core/print-sequential appears to be private. Solved with (let [printing-fn #'clojure.core/print-sequential]...
- pr-on does not seem to exist anymore. I assume it functions just as 'pr' but using a Writer of your own choosing
- *iderefs* got to be ^:dynamic

After that, the print-method for IDerefs can be compiled, but when testing it on the provided example, I get an
Execution error (StackOverflowError) at java.lang.ThreadLocal/get (ThreadLocal.java:163).
[#atom[

It appears '[#atom[' printed out is a start of the print-method implemented by cider.nrepl and I'm still searching in this direction.
Is there an updated solution to this problem (print cyclic refs with unlimited depth, but avoid printing the
value of any reference object more than once)?

kind regards,
Dieter

dieter.v...@gmail.com

unread,
Jan 1, 2022, 9:07:09 AM1/1/22
to Clojure
I also notice that
user> (((methods print-method) clojure.lang.Atom) (atom 5) *out*)
#atom[5 0x403721b8]nil
user> (atom 5)
#<Atom@2cc2327d: 5>

and I could not reproduce the printing of '#<Atom@2cc2327d: 5>' with any of (keys (methods print-method))...
Reply all
Reply to author
Forward
0 new messages