Thanks guys. I had a feeling that it wasn't doing the calculation twice the
way it was coded in the book.
Ryan
On Tuesday, July 23, 2013 11:23:21 AM UTC-4, Lars Nilsson wrote:
>
> On Tue, Jul 23, 2013 at 11:12 AM, Baishampayan Ghose
> >
> wrote:
> > It's definitely got to do with the code, th
On Tue, Jul 23, 2013 at 11:12 AM, Baishampayan Ghose wrote:
> It's definitely got to do with the code, the right way to test it out
> will be to wrap the form in a function and then calling it twice. Like
> so -
>
> (time
> (let [x (fn [] (Thread/sleep 2000)
>(+ 1 1))]
>
It's definitely got to do with the code, the right way to test it out
will be to wrap the form in a function and then calling it twice. Like
so -
(time
(let [x (fn [] (Thread/sleep 2000)
(+ 1 1))]
[(x) (x)]))
;=> "Elapsed time: 4002.0 msecs"
;=> [2 2]
Hope that helps
There is an example in the book The Joy of Clojure on p.262 that uses
futures that I evaluated in the REPL.
user> (time
(let [x (future (do (Thread/sleep 2000)
(+ 1 1)))]
[@x @x]))
"Elapsed time: 2000.809 msecs"
[2 2]
I figured that taking out the future would cause the execution to t