I think versions with `for` is a hell more readable.
I vote for this:
(def cc
(for [i (range 256)]
(.GetColor ctf (/ i 255.0))))
воскресенье, 24 июня 2012 г., 16:15:14 UTC+6 пользователь Michael Klishin
написал:
>
> Antonio Recio:
>
> > And I would know if this is correct conversion in clojure?
> > (def cc
> > [(for [i (range 256)]
> > (.. ctf GetColor (/ i 255.0)))])
>
> It is correct in the sense that it will do the same thing. If you have a
> collection and need to calculate
> a value for every element in it and return the list of results, this is
> what clojure.core/map is for:
>
> (map (fn [i] (.getColor ctf (/ i 255.0))) (range 256))
>
> or
>
> (defn color-for
> [i]
> (.getColor ctf (/ i 255.0)))
>
> (map color-for (range 256))
>
> Keep in mind that both range and map return lazy sequences. You can force
> their evaluation by wrapping
> the entire thing into (doall ...).
>
> More examples at http://clojuredocs.org/clojure_core/clojure.core/map
>
> MK
>
> [email protected]
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en