Hi Rich, It is a small real problem: in the book I demonstrate an incorrect, stack-consuming recursion that blows up on a deeply nested structure. When the recursion is fixed, it *still* blows up because the REPL cannot print it, so I introduce *print-level*.
I don't think printing super-deep structures at the REPL is particularly important, but I am curious how you would go about implementing it. Stuart > On Jan 21, 8:43 pm, Stuart Halloway <stuart.hallo...@gmail.com> wrote: >> Consider the function deeply-nested: >> >> (defn deeply-nested [n] >> (loop [n n >> result [:bottom]] >> (if (= n 0) >> result >> (recur (dec n) [result])))) >> >> If you print it at the REPL for small values of n, no problem: >> >> (deeply-nested 25) >> -> [[[[[[[[[[[[[[[[[[[[[[[[[[:bottom]]]]]]]]]]]]]]]]]]]]]]]]]] >> >> But for large values of n: >> >> (deeply-nested 1000000) >> -> java.lang.StackOverflowError >> >> You can dodge this problem by setting *print-level* >> >> (set! *print-level* 25) >> -> 25 >> (deeply-nested 1000000) >> -> [[[[[[[[[[[[[[[[[[[[[[[[[#]]]]]]]]]]]]]]]]]]]]]]]]] >> >> But what if you really want to print a deeply nested structure? What >> is the simplest modification to core_print.clj that gets the job >> done? >> Is this a good use case for trampoline, or is there a better >> Clojurish >> way? > > Is this a real problem or a theoretical one? > > Rich > > > --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---