I'd like to focus the attention back to a specific example. See the first code snippet at http://clojure.org/concurrent_programming.
(import '(java.util.concurrent Executors)) (defn test-stm [nitems nthreads niters] (let [refs (map ref (replicate nitems 0)) pool (. Executors (newFixedThreadPool nthreads)) tasks (map (fn [t] (fn [] (dotimes [n niters] (dosync (doseq [r refs] (alter r + 1 t)))))) (range nthreads))] (doseq [future (. pool (invokeAll tasks))] (. future (get))) (. pool (shutdown)) (map deref refs))) Many people new to Clojure will be attracted to this page because they will have heard that one of the strengths of Clojure is how good it is for concurrent programming. I believe the purpose of this example is to demonstrate how much easier it is to program with Clojure refs instead of Java locks. Certainly this code is much shorter than similar Java code. There is a paragraph before the code that explains what the code does and there are no comments within the code. Suppose you had been studying Clojure for one week before coming across this code. Would you know what was going on here? Let's see ... we've got an anonymous function that uses an anonymous function which iterates some number of times calling dosync on a doseq ... alter changes the value of a ref ... it uses a future ... My fear is that many developers will become discouraged and stop trying to learn Clojure, fearing that it's just too hard. I think we need to work to minimize those kinds of reactions to sample code. Adding some comments to non-obvious code is one way to do that. I don't mean to single out this one example. Many examples of Clojure code seem equally daunting to me and most Clojure code seems to contain no comments at all. -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---