On Tue, Jul 9, 2013 at 10:46 AM, Gary Trakhman <gary.trakh...@gmail.com>wrote:

> The TCO macro already exists: https://github.com/cjfrisz/clojure-tco
>
>
That is super cool.

I feel compelled to observe that using a continuation monad run by a
trampoline also allows for tail call elimination:

user=> (require '[monads.cont :as c] '[monads.core :refer [>>= return]])
nil
user=> (declare od?)
#'user/od?
user=> (defn evn? [x] (if (zero? x) (return true) (od? (dec x))))
#'user/evn?
user=> (defn od? [x] (if (zero? x) (return false) (>>= (return nil) (fn [_]
(evn? (dec x))))))
#'user/od?
user=> (c/run-cont (evn? 5000000))
true

But the result is about 2x slower than what the clojure-tco macro produces
(around 600ms vs around 300ms, for me).

-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks, which
may be sweet, aromatic, fermented or spirit-based. ... Family and social
life also offer numerous other occasions to consume drinks for pleasure."
[Larousse, "Drink" entry]

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to