On Tue, Jan 3, 2012 at 6:05 PM, meb <meba...@gmail.com> wrote:
> I see two fairly straightforward paths to simulating multiple returns
> without breaking existing callers. Both take advantage of thread-local
> state and establish one convention for the caller ...

Both of them have reentrancy problems -- in the push-thread-bindings
case, only if a caller doesn't use the extra values (and pop the
thread bindings), but that may be a common case.

You mentioned memoization, though, which might offer a superior
alternative in the case of pure functions:

(let [foo-memo-cache (atom {})
      bar-memo-cache (atom {})]
  (defn foo ...)
  (defn bar ...))

...

(foo x y)
(bar x y)

The idea here is that foo and bar can see and modify one anothers'
memoization caches. If computing (foo x y) can cheaply also compute
(bar x y), then it can stuff that into bar's memoization cache and
return its own result; the subsequent call to (bar x y) then doesn't
duplicate the computation, as the result's cached. Works well only if
foo and bar are (conceptually) pure functions. May be done so that foo
and bar can be called in either order. No problems with reentrancy or
thread-safety.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to