Tackling my first Clojure project, a Graphical HTTP Benchmarker in Clojure
blog.andrewvc.com
blog.andrewvc.com
(defn stats [requests-state]
"Returns a mapping of RequestsState http states states to counts"
(reduce
(fn [stats request]
(let [r @request
state (:state r)
status (:status r)
statuses (:statuses stats)]
(assoc stats
:total (inc (stats :total 0))
state (inc (stats state 0))
:statuses (assoc statuses status (inc (statuses status 0)))
:progress (if (not= state :untried)
(inc (stats :progress 0))
(stats :progress 0)))))
{:statuses {}}
(flatten (:grid @requests-state))))
Could be written like so: (defn stats [requests-state]
"Returns a mapping of RequestsState http states states to counts"
(reduce
(fn [{statuses :statuses total :total :as stats} request]
(let [{state :state status :status} @request]
(assoc stats
:total (inc (or total 0))
state (inc (stats state 0))
:statuses (assoc statuses status (inc (statuses status 0)))
:progress (if (not= state :untried)
(inc (stats :progress 0))
(stats :progress 0)))))
{:statuses {}}
(flatten (:grid @requests-state)))) (fn [stats request]
(let [{:keys [statuses total]} stats
{:keys [state status]} @request]
...)) (and (>= status 200) (< status 300))
becomes: (<= 200 status 299)
Go Clojure.Unfortunately, most books/articles on Clojure and Scala assume you know Java.
Really, to get started with Clojure, all you need to do is install Leiningen (https://github.com/technomancy/leiningen) and type "lein repl" in a terminal window. No ant, wars, or jvm's to think about :)
Really though, you should know how to browse javadocs, and the java ecosystem.
It is true that you can use clojure wrappers around java libs (and its nicer too) but a lot of them don't expose the full functionality of their java counterparts, and clojure's young enough that to understand how they work you'll have to dive heavily into their java interop.
Before the clojure.java.io namespaces was created, it used to be necessary to interact directly with those classes for even basic usage. (Kids these days! They've got it so easy.)
The web application ecosystem can be a bit intimidating to peace-loving programmers with all its talk of wars, but even that is changing with deployment options like Elastic Beanstalk and Heroku.
Anyway, you hear horror stories about Enterprise Java Beans, dependency injection frameworks, Maven, and whatnot, but you never see any of that in everyday Clojure.
Let me know if it's missing anything! You don't need to worry about any sort of jvm ant wars, either. Use Leiningen.