On Sat, Jun 19, 2010 at 4:10 PM, Michał Marczyk
<michal.marc...@gmail.com> wrote:
> (defn fact [n]
>  (loop [n n r 1]
>    (if (zero? n)
>      r
>      (recur (dec n) (* r n)))))

Huh? That doesn't look like it's going to work at all.

1) 1 is primitive, we know that, accept it
2) we don't know the type of n, what will (* r n) be?
3) BOOM!

My suggestion is to stop it with the contrived examples. Start showing some
real code, real problems in your real programs. Using loop/recur is already
the beginning of code smell for anything that is not performance sensitive.

(defn fact
  ([n] (fact n 1))
  ([n r] (if (zero? n)
          r
          (recur (dec n) (* r n)))))

Sleep soundly.

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