Thank you for the answer. Could trampoline benefit for being enhanced by allowing an explicit "escaping" for a return value of type function (that could also work for other return types, but would not be necessary for the common case).
Something like these : - common usage : as usual user=> (def myClosure #(prn "Hello")) #'user/myClosure user=> (trampoline myClosure) "Hello" - explicit escape via a "noboing" (or "stop" or "return" any name you like) call (works for any return type) : user=> (def myClosure (noboing #(prn "Hello"))) #'user/myClosure user=> (trampoline myClosure) #'user/myClosure And it could be implemented as : public final class org.clojure.lang.NoBoingWrapper { public final Object returnInstance; public NoBoingWrapper(Object returnInstance) { this.returnInstance = returnInstance; } } (defn noboing [returnInstance] (org.clojure.lang.NoBoingWrapper. returnInstance)) and the modification of trampoline along these lines : (defn trampoline [f] (let [ret (f)] (cond f (fn? ret) (recur ret) (instance? org.clojure.lang.NoBoingWrapper f) (.returnInstance f) else ret))) HTH, -- Laurent On Nov 26, 10:38 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: > On Nov 26, 2008, at 4:32 PM, lpetit wrote: > > > I've maybe missed something, but will this work if one wants to make > > the final return value of the tail call a closure ? > > Along the same lines of this being a manual way to do TCO, that issue > will need to be handled manually as well. Here's what (doc trampoline) > has to say about it: > > user=> (doc trampoline) > ------------------------- > clojure.core/trampoline > ([f] [f & args]) > trampoline can be used to convert algorithms requiring mutual > recursion without stack consumption. Calls f with supplied args, if > any. If f returns a fn, calls that fn with no arguments, and > continues to repeat, until the return value is not a fn, then > returns that non-fn value. Note that if you want to return a fn as a > final value, you must wrap it in some data structure and unpack it > after trampoline returns. > nil > > --Steve --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---