Re: Question about future

2009-12-09 Thread lpetit
Please also note the existence of (future-call), which takes a no-arg fn instead of a body, HTH, -- Laurent On 25 nov, 17:21, David Brown wrote: > 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 > >s

Re: Question about future

2009-11-26 Thread John Harrop
On Thu, Nov 26, 2009 at 2:11 AM, Christophe Grand wrote: > On Thu, Nov 26, 2009 at 8:05 AM, Robert Campbell wrote: > >> If you have this: >> >> user> (def f (future (Thread/sleep 2) :done)) >> #'user/f >> user> @f ; this immediate deref blocks for 20 sec, finally returning >> :block >> :done

Re: Question about future

2009-11-25 Thread Christophe Grand
On Thu, Nov 26, 2009 at 8:05 AM, Robert Campbell wrote: > If you have this: > > user> (def f (future (Thread/sleep 2) :done)) > #'user/f > user> @f ; this immediate deref blocks for 20 sec, finally returning > :block > :done > user> @f ; returns immediately > :done > > What is actually happ

Re: Question about future

2009-11-25 Thread Robert Campbell
If you have this: user> (def f (future (Thread/sleep 2) :done)) #'user/f user> @f ; this immediate deref blocks for 20 sec, finally returning :block :done user> @f ; returns immediately :done What is actually happening when you call the first @f? You are waiting for the function to finish e

Re: Question about future

2009-11-25 Thread Hong Jiang
Thanks. Yeah, after adding a call to shutdown-agents, the process no longer hangs. On Nov 25, 1:15 pm, Kevin Downey wrote: > future also uses the same threadpool as agents, so once you call > future the threadpool spins up, and just sort of sits around for a > while before the jvm decides to exit

Re: Question about future

2009-11-25 Thread Kevin Downey
future also uses the same threadpool as agents, so once you call future the threadpool spins up, and just sort of sits around for a while before the jvm decides to exit, which is why the program would sit around for 50 seconds On Wed, Nov 25, 2009 at 10:30 AM, Hong Jiang wrote: > Thanks for your

Re: Question about future

2009-11-25 Thread Hong Jiang
Thanks for your replies David and Sean. Yes, I made a mistake thinking that future takes a function and its arguments, so the function was never called in my program. On Nov 25, 8:21 am, David Brown wrote: > On Tue, Nov 24, 2009 at 09:04:38PM -0800, Hong Jiang wrote: > >Hi all, > > >I'm new to Cl

Re: Question about future

2009-11-25 Thread Meikel Brandmeyer
Hi, On Nov 25, 6:04 am, Hong Jiang wrote: > 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) >    

Re: Question about future

2009-11-25 Thread David Brown
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) > %) >

Re: Question about future

2009-11-25 Thread Sean Devlin
I'm not quite sure what you're seeing. You might want to use the time macro to help. Here's what I was able to do: user=> (time ((fn [] (let [f (future (#(do (Thread/sleep 5000) %) 5)) g 7] (+ g @f) "Elapsed time: 4975.917889 msecs" 12 Sean On Nov 25, 12:04 am, Hong Jiang wrote: > Hi all,

Question about future

2009-11-25 Thread Hong Jiang
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))) (println (testf)) I'm expec