On Sat, Apr 12, 2014 at 5:13 AM, Cecil Westerhof <cldwester...@gmail.com>
wrote:
> But it looks a ‘little’ cumbersome. Is there a better way to do this?

Here's another way. Not the best way, but I offer it to introduce you
to atoms [1] if you're not familiar yet.

[1] http://clojure.org/atoms

(def numbers '(4 6 8 10))

(def needed-times (atom []))

(doseq [number numbers]
  (let [start   (now)
        elapsed (fn elapsed []
                  (- (.getTimeInMillis (now)) (.getTimeInMillis start)))]
    (foo number)
    (swap! needed-times conj (elapsed))))

--
John



>
> At the moment I have the following:
>     (def numbers     '(4 6 8 10))
>
>     (doseq [number numbers]
>            (foo number))
>
> The call foo generates some output, but I also want to save the time it
> took for the call to complete. At the moment I am thinking about
> something like:
>     (def numbers     '(4 6 8 10))
>
>     (def ^:dynamic needed-times ())
>     (doseq [number numbers]
>            (let [start (now)]
>                 (foo number)
>                 (def ^:dynamic needed-times
>                                (cons (- (.getTimeInMillis (now))
(.getTimeInMillis start))
>                                      needed-times))))
>
>
>
> Also if I need to use several points in time, do I keep nesting ‘let’,
> or is there a better way?
>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to