Re: StackOverflowError possible with seq ?

2010-01-22 Thread mudphone
Hi Robert,

I tracked down the source of the StackOverflowError in my code.  It
boils down to the following similar (to your example) code snippet.
Although, on my machine, this example gives the stack overflow, rather
than the OOM error.

(def acoll (ref []))
(doseq [i (range 1 3000)]
  (println i: i)
  (dosync
   (alter acoll concat [i])))
(println count: (count @acoll))

You can avoid this stack overflow with a doall or just replacing
concat [i] with conj i.

This seems obvious in hind-sight of course...

Thanks for your help.
Kyle

On Jan 18, 6:36 am, kirschkernkissen robert.ste...@gmail.com wrote:
 Hi Kyle!

 I encountered the same problem:

 (defn stack-fail
   returns an empty lazy seq
   [l i]
   (if ( i 0)
     (recur (remove #{1} (concat l '(1))) (dec i))
     l))

 (def foo (stack-fail () 1000))

 foo
 ; Evaluation aborted.

 if you call a non-lazy function (e.g. doall) on the collection from
 time to time this wont happen.

 Rgds, Robert

 On 15 Jan., 00:05, mudphone kyle...@gmail.com wrote:



  Is it possible that the Clojure core seq function can cause a stack
  overflow (since it calls itself)?

  Or is there some other manner in which misuse of a lazy seq could
  cause this?  In the stack trace below, I'm seeing repeated calls to
  seq in clojure core, until the stack is blown.

  Thanks,
  Kyle

  Exception in thread main java.lang.StackOverflowError
  (session_master_boot.clj:19)
          at clojure.lang.Compiler.eval(Compiler.java:4617)
          at clojure.lang.Compiler.eval(Compiler.java:4593)
          at clojure.lang.Compiler.load(Compiler.java:4931)
          at clojure.lang.Compiler.loadFile(Compiler.java:4898)
          at clojure.main$load_script__6637.invoke(main.clj:210)
          at clojure.main$init_opt__6640.invoke(main.clj:215)
          at clojure.main$initialize__6650.invoke(main.clj:243)
          at clojure.main$null_opt__6672.invoke(main.clj:268)
          at clojure.main$legacy_script__6687.invoke(main.clj:299)
          at clojure.lang.Var.invoke(Var.java:359)
          at clojure.main.legacy_script(main.java:32)
          at clojure.lang.Script.main(Script.java:20)
  Caused by: java.lang.StackOverflowError
          at clojure.core$seq__3835.invoke(core.clj:103)
          at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
          at clojure.lang.LazySeq.sval(LazySeq.java:42)
          at clojure.lang.LazySeq.seq(LazySeq.java:56)
          at clojure.lang.RT.seq(RT.java:440)
          at clojure.core$seq__3835.invoke(core.clj:103)
          at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
          at clojure.lang.LazySeq.sval(LazySeq.java:42)
          at clojure.lang.LazySeq.seq(LazySeq.java:56)
          at clojure.lang.RT.seq(RT.java:440)
          at clojure.core$seq__3835.invoke(core.clj:103)
          at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
          at clojure.lang.LazySeq.sval(LazySeq.java:42)
          at clojure.lang.LazySeq.seq(LazySeq.java:56)
          at clojure.lang.RT.seq(RT.java:440)
          at clojure.core$seq__3835.invoke(core.clj:103)
          at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
          at clojure.lang.LazySeq.sval(LazySeq.java:42)
          at clojure.lang.LazySeq.seq(LazySeq.java:56)
          at clojure.lang.RT.seq(RT.java:440)

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


Re: StackOverflowError possible with seq ?

2010-01-18 Thread kirschkernkissen
Hi Kyle!

I encountered the same problem:

(defn stack-fail
  returns an empty lazy seq
  [l i]
  (if ( i 0)
(recur (remove #{1} (concat l '(1))) (dec i))
l))

(def foo (stack-fail () 1000))

foo
; Evaluation aborted.

if you call a non-lazy function (e.g. doall) on the collection from
time to time this wont happen.

Rgds, Robert

On 15 Jan., 00:05, mudphone kyle...@gmail.com wrote:
 Is it possible that the Clojure core seq function can cause a stack
 overflow (since it calls itself)?

 Or is there some other manner in which misuse of a lazy seq could
 cause this?  In the stack trace below, I'm seeing repeated calls to
 seq in clojure core, until the stack is blown.

 Thanks,
 Kyle

 Exception in thread main java.lang.StackOverflowError
 (session_master_boot.clj:19)
         at clojure.lang.Compiler.eval(Compiler.java:4617)
         at clojure.lang.Compiler.eval(Compiler.java:4593)
         at clojure.lang.Compiler.load(Compiler.java:4931)
         at clojure.lang.Compiler.loadFile(Compiler.java:4898)
         at clojure.main$load_script__6637.invoke(main.clj:210)
         at clojure.main$init_opt__6640.invoke(main.clj:215)
         at clojure.main$initialize__6650.invoke(main.clj:243)
         at clojure.main$null_opt__6672.invoke(main.clj:268)
         at clojure.main$legacy_script__6687.invoke(main.clj:299)
         at clojure.lang.Var.invoke(Var.java:359)
         at clojure.main.legacy_script(main.java:32)
         at clojure.lang.Script.main(Script.java:20)
 Caused by: java.lang.StackOverflowError
         at clojure.core$seq__3835.invoke(core.clj:103)
         at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
         at clojure.lang.LazySeq.sval(LazySeq.java:42)
         at clojure.lang.LazySeq.seq(LazySeq.java:56)
         at clojure.lang.RT.seq(RT.java:440)
         at clojure.core$seq__3835.invoke(core.clj:103)
         at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
         at clojure.lang.LazySeq.sval(LazySeq.java:42)
         at clojure.lang.LazySeq.seq(LazySeq.java:56)
         at clojure.lang.RT.seq(RT.java:440)
         at clojure.core$seq__3835.invoke(core.clj:103)
         at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
         at clojure.lang.LazySeq.sval(LazySeq.java:42)
         at clojure.lang.LazySeq.seq(LazySeq.java:56)
         at clojure.lang.RT.seq(RT.java:440)
         at clojure.core$seq__3835.invoke(core.clj:103)
         at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
         at clojure.lang.LazySeq.sval(LazySeq.java:42)
         at clojure.lang.LazySeq.seq(LazySeq.java:56)
         at clojure.lang.RT.seq(RT.java:440)
-- 
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

Re: StackOverflowError possible with seq ?

2010-01-18 Thread mudphone
Hi Robert,

Thanks for your reply!  Very interesting.  I see what you're saying.
But, your code results in a OutOfMemoryError, rather than a
StackOverflow.

At least, that's what I see on my machine.  Are you seeing the same?

Is there some way that this same concept could lead to a
StackOverflow?

Thanks,
Kyle

On Jan 18, 6:36 am, kirschkernkissen robert.ste...@gmail.com wrote:
 Hi Kyle!

 I encountered the same problem:

 (defn stack-fail
   returns an empty lazy seq
   [l i]
   (if ( i 0)
     (recur (remove #{1} (concat l '(1))) (dec i))
     l))

 (def foo (stack-fail () 1000))

 foo
 ; Evaluation aborted.

 if you call a non-lazy function (e.g. doall) on the collection from
 time to time this wont happen.

 Rgds, Robert

 On 15 Jan., 00:05, mudphone kyle...@gmail.com wrote:



  Is it possible that the Clojure core seq function can cause a stack
  overflow (since it calls itself)?

  Or is there some other manner in which misuse of a lazy seq could
  cause this?  In the stack trace below, I'm seeing repeated calls to
  seq in clojure core, until the stack is blown.

  Thanks,
  Kyle

  Exception in thread main java.lang.StackOverflowError
  (session_master_boot.clj:19)
          at clojure.lang.Compiler.eval(Compiler.java:4617)
          at clojure.lang.Compiler.eval(Compiler.java:4593)
          at clojure.lang.Compiler.load(Compiler.java:4931)
          at clojure.lang.Compiler.loadFile(Compiler.java:4898)
          at clojure.main$load_script__6637.invoke(main.clj:210)
          at clojure.main$init_opt__6640.invoke(main.clj:215)
          at clojure.main$initialize__6650.invoke(main.clj:243)
          at clojure.main$null_opt__6672.invoke(main.clj:268)
          at clojure.main$legacy_script__6687.invoke(main.clj:299)
          at clojure.lang.Var.invoke(Var.java:359)
          at clojure.main.legacy_script(main.java:32)
          at clojure.lang.Script.main(Script.java:20)
  Caused by: java.lang.StackOverflowError
          at clojure.core$seq__3835.invoke(core.clj:103)
          at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
          at clojure.lang.LazySeq.sval(LazySeq.java:42)
          at clojure.lang.LazySeq.seq(LazySeq.java:56)
          at clojure.lang.RT.seq(RT.java:440)
          at clojure.core$seq__3835.invoke(core.clj:103)
          at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
          at clojure.lang.LazySeq.sval(LazySeq.java:42)
          at clojure.lang.LazySeq.seq(LazySeq.java:56)
          at clojure.lang.RT.seq(RT.java:440)
          at clojure.core$seq__3835.invoke(core.clj:103)
          at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
          at clojure.lang.LazySeq.sval(LazySeq.java:42)
          at clojure.lang.LazySeq.seq(LazySeq.java:56)
          at clojure.lang.RT.seq(RT.java:440)
          at clojure.core$seq__3835.invoke(core.clj:103)
          at clojure.core$concat__3960$fn__3970.invoke(core.clj:427)
          at clojure.lang.LazySeq.sval(LazySeq.java:42)
          at clojure.lang.LazySeq.seq(LazySeq.java:56)
          at clojure.lang.RT.seq(RT.java:440)
-- 
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