On 27 nov, 18:09, Rich Hickey <[EMAIL PROTECTED]> wrote:
> > > (defn trampoline [f]
> > >   (let [ret (f)]
> > >      (cond f
> > >        (fn? ret) (recur ret)
> > >        (instance? org.clojure.lang.NoBoingWrapper f) (.returnInstance
> > > f)
> > >        else ret)))
> I considered that, and it's still a possibility, but I don't want
> people thinking they need to call (trampoline-return x) all the time.
> The only time you need to wrap the return value is when the result is
> an actual fn.

Well, actually the above implementation allows to not use (trampoline-
return) for all common cases, and would just be a standard work-around
in the fn-as-value returning case. Isn't it more a matter of where to
put the focus on the documentation.

Let's try a modified version of trampoline doc with (trampoline-
return) explanation added :
"
   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, wrap it in a call to trampoline-return (or wrap your
fn in some data structure of your own, and unpack it manually after
trampoline returns).
"

> But it is nice to do the unwrapping in trampoline itself.
Yes, there is just one special case, why not provide a standard way to
handle it ?

> My thinking is that such mutually-recursive state machines are
> designed of-a-piece, so any wrapping protocol would be local, and I
> wanted to minimize the amount of cruft one would have to add to use a
> trampoline.
>
> Rich
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to