> i wasn't really trying to achieve anything useful - just messing
> around and see where i get.
>
> now i'm here:
> (defrecord point [x y z])
> (defn genPoints [n]
> (let [random (new Random)
> randomInt #(.nextInt random)
> randomPoint #(new point (randomInt) (randomInt) (randomInt))]
> (repeatedly n randomPoint)))
>
> is there a way to avoid writing (randomInt)(randomInt)(randomInt) and
> instead something like (magic (repeatedly 3 randomInt))?
This is how I would write it -
(defrecord Point [x y z])
;;; Only needed in pre Clojure 1.3.0
;;; In Clojure 1.3.0, ->Point will be generated automatically
;; (defn ->Point
;; [x y z]
;; (Point. x y z))
(defn gen-points [n]
(let [random (java.util.Random.)
random-int #(.nextInt random)
random-point #(apply ->Point (repeatedly 3 random-int))]
(repeatedly n random-point)))
Hope this helps.
Regards,
BG
--
Baishampayan Ghose
b.ghose at gmail.com
--
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