Clojure Weekly, Jun 12th, 2014
Welcome to another stellar issue of Clojure Weekly! Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!
how is it possible to intern macros in clojure? - Stack Overflow Interning is the operation of storing a new symbol to var mapping pair in a namespace instance. The var can point to a function or a macro or something else. After interning the new symbol starts to work exactly like any other created using def/defn. Interning can be useful when the definition is done at runtime rather than compile time (a special case indeed, but similar to what is called meta-programming in other languages). This stack overflow question was answered to understand what to do in case of a macro, which turns out to be just some metadata away. The interned macro is then used in the context of the namespace it was defined into.
Automated Browser-based Testing with Clojure — An Architect's View When the time will come to have some browser automation covering the main feature of our app, I want to be ready. I'm very reluctant to have a comprehensive suite of browser based tests and make it part of a top-down process, but I'm happy to have a sanity automation click-around that tells me if something important is severely damaged. It looks like Gregoire's clj-webdriver is that nifty lib, a Selenium WebDriver wrapper that can be used easily from Clojure. This post by Sean Corfield explains and to set it up.
ClojureDocs - clojure.core/with-redefs with-redefs is the less sophisticated binding cousin. It changes the var root of a var for all the executing threads instead of being selective as binding is. It does this to all vars, those marked :^dynamic and those that are not. This brutal approach doesn't have a lot of application in normal code, since it implies a global state change that other portion of the code might not be aware of. This is the reason why it is preferable to binding to mock out a function in testing. with-redefs will operate as expected even in case where tests are concurrent.
ClojureDocs - clojure.core/not-empty This little function seems useless but it enables better idiomatic Clojure. not-empty on a collection returns nil when the collection is empty. As we know, Clojure collection emptiness does not equal nil, that is (= nil []) is false. But (= nil (not-empty [])) is true. Why would you need that? To enable when-let forms on collections. If a function needs to create/process a collection first thing and only proceed if there is at least one element in the collection (maybe doing expensive stuff) (when-let [mycoll (not-empty (fetch-elements))]) only evaluates when there is something in the collection.
arrdem/oxcart Oxcart is another (GSoC) attempt to speed-up Clojure at the price of a reduced or removed dynamicity. It is a Clojure rewrite of the reader, analyzer, emitter triad that compared to the tools.* approach doesn't seek Clojure compliance (other than the pure runtime). Compared instead to Alexander Yakushev's Skummet or the Rich' fastload branch, this is written in Clojure while the formers are taking it from the current Java implementation. Several interesting ideas in this project, but mainly the compilation of functiond belonging to the same namespace to a single class (instead of a class per function) or the entire program to a single class, thus allowing drastic optimisations once the entire requirements in term of bytecode are all collected in the same place.
clojure-classes/graph-w-legend.png at master · Chouser/clojure-classes Another great class diagram by CHouser. It's from 2009 but it's still a great "getting-around" reference considering the amount of classes and their relationship in Clojure core.












