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

mich...@defprotocol.org

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to