The compiler uses recursive descent in its analysis.  Given a VM call stack 
that does not grow, there will always been some input that causes the 
compiler to blow stack.  In the case of cond, the macro expands into a 
nested if statements.  Given enough clauses, you get the result you have 
experienced.

There are several solutions.

(1) Rewrite the compiler to make the analysis use an explicite 
(heap-allocated) stack.    That would be a lot of work.  It's not going on 
my short list anytime soon.
(2) Rewrite the compiler to run on a separate thread and create a way (a 
command-line option, for example) to configure the stack size on the 
compiler thread.
(3) Recompile (actually re-link) Clojure.Main.exe to have a larger stack 
size.   See http://msdn.microsoft.com/en-us/library/8cxs58a6(v=vs.100).aspx
(4) Edit the Clojure.Main.exe executable to have a larger stack size.  The 
EDITBIN.EXE program is often used for this. 
 See http://msdn.microsoft.com/en-us/library/xd3shwhf(v=vs.110).aspx.
(5) Break up your cond into several (non-nested) statements.

Solutions (1) through (4) require access to the CLR compiler toolset or 
Visual Studio.

-David


On Saturday, November 17, 2012 10:37:38 AM UTC-6, FC wrote:
>
> When ClojureCLR (.NET 3.5 build) evals a cond form with 1024 clauses it 
> throws a StackOverflowException.
>
> Cond example code in pastebin: http://pastebin.com/K4QQmjNF
> Save the example code to bigcond.clj and run Clojure.Main like: 
> Clojure.Main bigcond.clj
>
> The number of cond clauses needed to cause a stack overflow varies. 
>
> Stack trace:
>
> System.StackOverflowException was unhandled
>
>
> > Clojure.dll!clojure.lang.ASeq.ASeq(clojure.lang.IPersistentMap meta) 
> Line 44 + 0xa bytes C#
>   
> Clojure.dll!clojure.lang.TypedArraySeq<object>.TypedArraySeq(clojure.lang.IPersistentMap
>  
> meta, object[] array, int index) Line 241 + 0xf bytes C#
>   
> Clojure.dll!clojure.lang.ArraySeq_object.ArraySeq_object(clojure.lang.IPersistentMap
>  
> meta, object[] array, int index) Line 734 + 0x19 bytes C#
>   Clojure.dll!clojure.lang.ArraySeq.create(object[] array) Line 41 + 0x44 
> bytes C#
>
>

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