The main example for recur on the special forms page (http://
clojure.org/special_forms#Special%20Forms--(recur%20exprs*)) is:

(def factorial
  (fn [n]
    (loop [cnt n acc 1]
       (if (zero? cnt)
            acc
          (recur (dec cnt) (* acc cnt))))))

I may not be be clojure jedi, but I've been learning the language for
a while.  I've never come across the notion that this is a code
smell.  I thought that the loop recur form was perfectly orthodox.

Also, the fact that the form above doesn't compile in the equal branch
does make me a little uneasy.

Rob

On Jun 19, 5:13 pm, David Nolen <dnolen.li...@gmail.com> wrote:
> 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