Re: Clojure Recursion (loop-recur) Questions

2012-11-27 Thread Andy Fingerhut
Yes, that wasn't very clear of me. Here is what I was thinking when writing that. In Scheme, which has general tail-call optimization, you will often find functions written where the programmer went out of their way to change it from recursive, but doesn't use tail calls, into something that r

Re: Clojure Recursion (loop-recur) Questions

2012-11-27 Thread Ben Wolfson
On Mon, Nov 19, 2012 at 6:24 PM, Andy Fingerhut wrote: > Clojure's loop/recur only implements tail recursion, not general tail-call > optimization. tail recursion is far more commonly used in languages that > have it than the general tail-call optimization to arbitrary functions. Can you explain

Re: Clojure Recursion (loop-recur) Questions

2012-11-27 Thread Andy Fingerhut
On Nov 27, 2012, at 8:17 PM, Curtis wrote: > Thank you Andy - This was fabulously helpful - I really appreciate your > explanation. > > Would you permit me to include your answer in a blog post about the above > question? Sure, use it however you like. Andy -- You received this message b

Re: Clojure Recursion (loop-recur) Questions

2012-11-27 Thread Ben Mabey
On 11/27/12 9:17 PM, Curtis wrote: Thank you Andy - This was fabulously helpful - I really appreciate your explanation. Would you permit me to include your answer in a blog post about the above question? On Monday, November 19, 2012 6:25:30 PM UTC-8, Andy Fingerhut wrote: If you are f

Re: Clojure Recursion (loop-recur) Questions

2012-11-27 Thread Curtis
Thank you Andy - This was fabulously helpful - I really appreciate your explanation. Would you permit me to include your answer in a blog post about the above question? On Monday, November 19, 2012 6:25:30 PM UTC-8, Andy Fingerhut wrote: > > If you are familiar with tail recursion, then loop/

Re: Clojure Recursion (loop-recur) Questions

2012-11-19 Thread Andy Fingerhut
If you are familiar with tail recursion, then loop/recur this is Clojure's way to achieve tail recursion. http://en.wikipedia.org/wiki/Tail_call The general tail call optimization mechanism as implemented in the programming language Scheme, for example, means that tail-position calls must not c

Clojure Recursion (loop-recur) Questions

2012-11-19 Thread Curtis
Clojure Koans - Recursion (defn recursive-reverse [coll] (loop [coll coll acc '() ] (if (= (count coll) 0) acc (recur (rest coll) (cons (first coll) acc)) ) ) ) I struggled with this one for a while - I don’t want to admit it, but honestly even though i have