Other people prefer having a form to explicitly request recursion.
That way, you are able to say explicitly in your code: I expect this
to be TCO-able, and have the compiler tell you if you are mistaken.
Another advantage of the explicit form is that it can be used
anonymously with `loop` as well as within functions (named or
otherwise).
user=> (loop [i 10 acc 0] (if (= i 0) acc (recur (- i 1) (+ i acc))))
55
user=> (defn foo [i acc] (if (= i 0) acc (recur (- i 1) (+ i acc))))
#'user/foo
user=> (foo 10 0)
55
Much neater than having to introduce some function or other construct
to act as a recursion point, and in many cases clearer than an
iteration construct. In Scheme you need a 'thing' to call.
--
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