On Tue, Nov 24, 2009 at 09:04:38PM -0800, Hong Jiang wrote:
>Hi all,
>
>I'm new to Clojure and playing with small programs. Today I wrote a
>snippet to figure out how future works:
>
>(defn testf []
> (let [f (future #(do
> (Thread/sleep 5000)
> %)
> 5)
> g 7]
> (+ g @f)))
You don't ever evaluate the function containing the sleep, you just
create it, and then immediately return 5.
Future contains an explicit do, so you can just do the steps in the
future:
[f (future
(Thread/sleep 5000)
5)
...
Or, if you want to get the function call in, you'll need to call it:
[f (future (#(do (Thread/sleep 5000) %) 5)) ...]
David
--
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