Is suspect this being a bug: When a recursive function call is used as a 
default value in a map, its tail position is not recognized. The problem 
can be easily demonstrated using the fixpoint function. The fixpoint 
function is usually defined as

> (defn fix [f x] (let [v (f x)] (if (= v x) x (recur f v))))  

To avoid the 'if' special form, we can use a map. The compiler rejects 
compilation and does not recognize (recur f v) to be correctly in tail 
position.

> (defn fix2 [f x] (let [v (f x)] ({x x} v (recur f v))))
CompilerException java.lang.UnsupportedOperationException: Can only recur 
from t
ail position, compiling:(NO_SOURCE_PATH:41)

Avoiding tail recursion lets fix2 compile but not execute properly:

> (defn fix2 [f x] (let [v (f x)] ({x x} v (fix2 f v))))
#'user/fix2
> (fix identity 1)
1
> (fix2 identity 1)
StackOverflowError   user/fix2 (NO_SOURCE_FILE:44)

Strange, isn't it!?

Dominikus

-- 
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