Re: Best practice for looping

2013-06-24 Thread P Martin
Great! Thanks so much for your help! On Monday, June 24, 2013 10:50:57 AM UTC-4, Gary Trakhman wrote: > > pst is printstacktrace, it's in the clojure.repl namespace and comes with > clojure. Sometimes lein or something makes it available automatically, > but if it isn't, you can (use 'clojure.

Re: Best practice for looping

2013-06-24 Thread Gary Trakhman
pst is printstacktrace, it's in the clojure.repl namespace and comes with clojure. Sometimes lein or something makes it available automatically, but if it isn't, you can (use 'clojure.repl) to get to it. http://clojure.github.io/clojure/clojure.repl-api.html#clojure.repl/pst Yes, switching to ma

Re: Best practice for looping

2013-06-24 Thread P Martin
Thanks a lot for tracing through my code! So, as I understand it, my loop/recur is correct, but I was not using map in a correct way within the vector functions. By the way, what is your (pst e*) line doing? Is that from a debugging library? I don't appear to have that in my clojure environment

Re: Best practice for looping

2013-06-22 Thread Gary Trakhman
I think the way to understand what's going on is to realize that laziness (coming from map) creates extra thunks, for each iteration, you're creating an extra stack frame to dereference the elements of the lazy seq. (defmacro lazy-seq "Takes a body of expressions that returns an ISeq or nil, and

Re: Best practice for looping

2013-06-22 Thread Gary Trakhman
Do you have the stack trace? It's not simple to run the code, but I made a github project so we can look at it easier. https://github.com/gtrak/grad-descent-test When I run (gradient-descent example-grad [0 1] 0.001 0.001) Here's the actual problem: grad-descent.core> (pst *e) StackOverflowError

Re: Best practice for looping

2013-06-22 Thread P Martin
Ah ok - so I may be using it wrong. I am not calling the function itself - I was simply trying to bind local variables in a loop. I have placed the code into gists for easier reading! https://gist.github.com/anonymous/5841405#file-core-clj https://gist.github.com/anonymous/5841420#file-vec-clj

Re: Best practice for looping

2013-06-21 Thread Cedric Greevey
An algorithm like that generating StackOverflowErrors suggests it's recursing deeply, which suggests you're not using recur *enough*. If the function calls itself, try to see if you can get that call into tail position and change it to "recur". On Fri, Jun 21, 2013 at 4:06 PM, P Martin wrote: >