Thanks to all for the excellent and quick responses.

David - you are right the variable should be called product not sum. This is 
just some poorly written Java code that I am translating to Clojure.

Justin - thanks for the idea on how to visualize such algorithms and the 
picture you shared. 

-----Original Message-----
From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of 
Alan Malloy
Sent: Wednesday, June 29, 2011 4:50 AM
To: Clojure
Subject: Re: Translating Java code with nested for loops

On Jun 29, 12:55 am, Ken Wesson <kwess...@gmail.com> wrote:
> On Wed, Jun 29, 2011 at 3:53 AM, Alan Malloy <a...@malloys.org> wrote:
> > This layout makes it fairly clear that the first element of total-
> > values is never being used, but it would be nice if we could say so
> > explicitly. So finally, we can wrap the whole thing in a let:
>
> > (defn calc [total-values daily-values]
> >  (let [interesting-values (next total-values)]
> >    (map-indexed
> >     (fn [i daily]
> >       (->> total-values
> >            (drop i)
> >            (map #(inc (/ % 100.0)))
> >            (reduce * daily)))
> >     daily-values)))
>
> Oops.

Not sure if this is what you're pointing out (a single word is tricky
to decipher), but I did forget to *use* interesting-values after
defining it: it should be the first form in the ->> list.

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