Your analysis is correct.  Note that adding a doall fixes the problem

user=> (def tl (reduce #(doall (concat %1 [%2])) [] (range 4000)))
#'user/tl
user=> (last tl)
3999

efficiency notwithstanding.

On Mar 28, 8:59 am, jim <jim.d...@gmail.com> wrote:
> Hey Rich,
>
> I found an interesting way to blow up the stack.
>
> user=> (def tl (reduce #(concat %1 [%2]) [] (range 3500)))
> #'user/tl
> user=> (last tl)
> java.lang.StackOverflowError (NO_SOURCE_FILE:0)
>
> The 3500 is probably specific to my environment.  I'm assuming that
> all the concats get deferred until needed and that the nested calls
> blow up the stack.
>
> Also, this works
>
> user=> (def tl (reduce #(conj %1 %2) [] (range 4000)))
> #'user/tl
> user=> (last tl)
> 3999
>
> Jim
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

  • Blow up jim
    • Re: Blow up William D. Lipe

Reply via email to