Re: Recur in an overloaded function does not work?

2016-04-20 Thread J.-F. Rompre
Ooops - my apologies (attempted correction below) Here is a horribly contrived example (sorry, that's all I can come up withht now rig) using recur across different arities of the same function, together with trampoline. (defn is-odd? ([n] (cond (< n 0) true (even? n) #(is-odd?

Re: Recur in an overloaded function does not work?

2016-04-20 Thread adrian . medina
I don't think you're missing anything James. It does not look like this example uses trampoline with the intended effect. On Wednesday, April 20, 2016 at 2:45:05 PM UTC-4, James Elliott wrote: > > Does trampoline really help in this case? I don’t see where we are ever > returning a new

Re: Recur in an overloaded function does not work?

2016-04-20 Thread James Elliott
Does trampoline really help in this case? I don’t see where we are ever returning a new function for trampoline to call, avoiding a new stack frame. It seems to me no different than simply calling the other arities directly in this example. What am I missing? On Wednesday, April 20, 2016 at

Re: Recur in an overloaded function does not work?

2016-04-20 Thread J.-F. Rompre
You can prevent stack consumption by using trampoline for tail-recursive calls to a different arity, and recur for same arity, something like: (defn find-comment-in-line ([s] (when (pos? (count s)) (if-let [cs (seq (comment-s? s))] ;; yes, a comment symbol found, ;;

Re: Recur in an overloaded function does not work?

2016-04-20 Thread J.-F. Rompre
You can prevent stack consumption by using trampoline for tail-recursive calls to a different arity, and recur for same arity, something like: (defn find-comment-in-line ([s] (when (pos? (count s)) (if-let [cs (seq (comment-s? s))] ;; yes, a comment symbol found, ;;

Re: Recur in an overloaded function does not work?

2016-04-19 Thread James Elliott
But recur does not do that. Recur does not call a function at all. It is the opposite of calling a function, it says “I want to loop, without the overhead of calling a function and creating a stack frame.” Recur is even used outside of functions entirely; it is how you iterate using the (loop

Re: Recur in an overloaded function does not work?

2016-04-19 Thread andmed
Thank you. That the point. If "recur" binds to fn, why it can not know the binding point as the function method based on the number of arguments passed to it? I mean it is clear that Clojure can't do that, but I can see no reason why it could or should not if we choose to implement such

Re: Recur in an overloaded function does not work?

2016-04-18 Thread James Elliott
And the reason for this is to be able to simulate tail-call optimization even though the Java VM doesn’t natively support that; recur can allow you to express things in a style that looks recursive, but does not suffer from stack space limitations that actual recursive calls do. If you actually

Re: Recur in an overloaded function does not work?

2016-04-18 Thread adrian . medina
Each arity defined for a particular Clojure function is actually a separate "method" under the hood for that particular functional instance. `recur` in Clojure should be thought of as more like a primitive looping construct than a recursive call to some named function. The documentation for

Recur in an overloaded function does not work?

2016-04-18 Thread andmed
Hello I am just a beginner Clojure programmer and I am unhappy with the way recur behaves in Clojure I have implemented kata from here https://github.com/alvarogarcia7/kata-formulation-find-comments/pull/3 What it does: it outputs 'comments' (sequences starting with "#" or "//") and ignores