Hello This is not written as functional code. You have to understand that :
(cons f futures) creates a new "version" of futures with f in front of it and cons *returns it to you*. Put another way,* futures is not modified by cons*. In your dotimes construct, the consed value is lost each loop. Have a look at loop/recur, map, and reduce, these are the backbone functions when programming in clojure. Also, do not use (def) inside a function, this is ugly. use let to define local bindings instead. -- Philippe. On Fri, May 23, 2014 at 10:16 AM, sorin cristea <srncris...@gmail.com>wrote: > > Hi all, > > do you have any idea how I can define a variable, global or inside a > function, used to store for example the FutureTask objects resulted from > ExecutorService submit(fn) call,I want to put all futures in a collection > and later call 'get' on each of them. bellow is a sample of that code: > > (defn sample-fc > [] > (def futures '()) > (dotimes [i 3] > (def f (. thread-pool (submit (fn [] ("task result !!!"))))) > (cons f futures) > ) > "shutdown the pool" > (. thread-pool shutdown) > (. thread-pool awaitTermination (. Long MAX_VALUE) (. TimeUnit SECONDS)) > > "go through all futures an call get on them" > (doseq [f futures] > (println (. f get)) > ) > ) > > when I do 'dosync' futures collection is empty, even if (def f (. > thread-pool (submit (fn [] ("task result !!!"))))) is a a non empty > object of type FutureTask(java.util.concurrent package). > > Do you know how to define 'futures' variable such that to keep all > returned future ? > > thanks, > Sorin > > -- > 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. > -- Philippe -- 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.