Clojure weekly, Nov 20, 2012
Welcome to this issue of Clojure Weekly. Clojure Weekly are just a few links to clojure-related posts, blogs, screencasts, presentations or podcasts I found over the Internet. I added a summary to each one of them so you can decide if you want to spend the time to look at the original! That’s it. Enjoy.
The BBC SICP Book Club Group Let me start this edition of clojure weekly with a shameless self promotion. I’m running yet another SICP book club here at BBC. Although the in-person meetings are for employee only, I’ll be happy to connect anyone interested in joining the book club. Also consider that most of the work is done at home while at meetings we are just making sure we agree on concepts and exercises from the book. http://groups.google.com/group/sicpbbc contains all the instructions to join in. We’ve just started and for this Thursday 12:30-13:30 (gmt+00) we’re going to review everything up to 1.1.5, including the Scheme interpreter installation.
clojure type conversion string to symbol - Stack Overflow Every now and then you’ll need a way to invoke functions given the function name as string instead of just typing the symbol in parenthesis for the actual invocation. You just need a combination of (symbol) and (resolve) to achieve the desired effect. So say you have a string “println” and you want to invoke the related clojure function: ((resolve (symbol “println”)) “foo”) is what you need!
Checkers for collections and strings · marick/Midje Wiki Midje is today a full-fledged feature rich test framework for clojure. I remember that when Brian Marick started the project, Midje was about experimenting with top-down BDD development in Clojure with just the basic features. Thanks to all the love received by the many contributors to the project, today Midje is mature and deserve to dig deeper into the wiki to find how it can make your life easier. This week I want to highlight collection matchers. There is everything you need to do collection matching on outputs and the documentation is organized by collection type.
flatland/drip Drip is yet another JVM launcher but the difference with nailgun is that drip doesn’t try to re-use the same JVM over and over. Drip creates a JVM based on invocation arguments and only in that case it uses it multiple times. You can see how many JVMs are active with drip ps and you can kill one by drip kill. You don’t need to kill JVMs your self, drip will automatically dismiss unused JVMs after a timeout. Unfortunately, it still doesn’t work properly with leiningen (that uses a specific trampoline configuration each time it is invoked) so you won’t notice any performance boost. But for any other Clojure (and JRuby or Java) use you’ll see the JVM startup time disappearing after first use. Cool.
Why Are You Not Using Functional Languages? A good thread on InfoQ. It starts as a poll but the comments are worth reading because they describe why FP adoption is problematic and a few “guerrilla tactics” to easy the learning curve for strongly OO environments. I’m more and more convinced that FP adoption is mainly a people problem, not a corporate or technological problem. The team in its majority should be relatively happy to be challenged with the adoption of a new paradigm, that is, the team should accept the pain of switching paradigm as a mean to acquire new knowledge. Once again it’s all about courage and will power.
Java 8 vs Scala: a Feature Comparison This infoQ article does a good job at comparing how the new Java 8 features compare to Scala when it comes to make a good use of high order functions. Java 8 does a decent job with list comprehension, while it becomes a little more problematic to solve the problem of wrapping functions around existing behaviour (like the Logger Traits example). In this case Java is missing a way for the inherited trait to access to the instance of the implementing class.
Clojure Weekly, March 19th, 2013
Welcome to another issue of Clojure weekly, my small routine blog contribution to the Clojure sphere! These are just a few links, normally 4/5 urls, pointing at articles, documentation, screencasts, podcasts or anything else that attracts my attention. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!
Pedestal Documentation - Build web apps in Clojure Potentially the biggest news this week, Relevancers released Pedestal, a brand new web application framework in Clojure. I skimmed through the documentation but couldn’t try out, will definitely do the next webapp with it. On the surface it remembered me of Compojure or the now gone Noir. It also sounds it is an integrated environment instead, where what used to be the custom made “ring stack” is now a default choice. Can’t say more for now, it is well documented and support on github and google groups. Give it a go if you can, I’m looking forward to it.
Separating code from tests: What is the vision? - Midje I was reasoning about later stages of development, when sources are already in their own files but at the same time I need to add more features. Since I’m not in the test file anymore, I thought I had to abandon my beloved top-down style, the midje “provided” keyword and the powerful “unfinished” block. Fear no more! This quick reply by Brian just tells you how to use unfinished in the source file and also gives you some reasons why you might even leave it after check-in.
tpope/vim-fireplace · GitHub Dear Clojure vim users (I’m not sure, but I have the impression there are just few of us), it seems that the glorious VimClojure life came to an end. VimClojure will be living in several different forms that are converging again to give you the best of the interactive Clojure experience in vim. Fireplace is a nREPL that replace the hg-server nailgun system of VimClojure. Along with it, the static part of VimClojure still lives in https://github.com/guns/vim-clojure-static project. Instructions are provided, I still have to migrate myself (my vim-clojure setup works great at the moment, not sure why I should migrate). If you’re starting today with vim and Clojure wait no more and follow the instruction listed on the github project page.
ClojureDocs - clojure.core/every-pred every-pred is a powerful filter-chaining tool. Say you have a collection of stuff and you want to alter elements based on a set of filters: number? even? or more complicated ones. (filter even? (filter number? ‘(1 2 3 :a :b))) holds up to a point if you don’t have too many filters. But what if you have a long list of filters? (filter (apply every-pred [number? even?]) ‘(1 2 3 :a :b)) fixes the problem for an arbitrary long list of predicates.
Not Lisp again… I enjoyed this reading about somebody who was there when MIT started teaching the Computer Science course in 1983. Lisp was resurrecting again in the form of Scheme and that course was taught until the last year. Not to mention that a book was extracted from that same course, the SICP. The examples in the book are some extracts from SICP up to chapter 1.3 where higher order functions are introduced.
algo.generic/src/main/clojure/clojure/algo/generic/functor.clj at master · clojure/algo.generic · GitHub Updating all values in a map sounds like a common operation in Clojure, but there is no dedicated function to it in the standard library. The closest match is update-in that only updates values if they match the given key. What I’m talking about here is global value update for each key. It turns out the solution is pretty straightforward using list comprehension with (into {} (for [[k v] m] [k (f v)]))) where m is the map and f is the updating function, for example inc. A generic update-values called fmap is included in algo.generic.functor, one of the old contrib now moved to the new repo.
Clojure weekly, Dec 17th, 2012
Here’s another instalment of Clojure Weekly. Clojure Weekly are just a few links to clojure-related posts, blogs, screencasts, presentations or podcasts I found over the Internet. I added a summary to each one of them so you can decide if you want to spend the time to look at the original! That’s it. Enjoy.
Clojure TDD demo (Robozzle) on Vimeo I keep going back to this Marick’s take on top-down TDD with Midje, which is a must see to download offline and practice constantly. This also happened recently when I was frustrated solving apparently simple functions. I’m very suspicious now if I feel a function is too complicated to solve. It should not happen. It’s an hint that my functional decomposition is not working at the right level. Working like Brian in this screencast helps me maintaining the complexity low and think the algorithm in terms of nouns and verbs that then translate into other functions. I can’t say if this is the best approach, what I know is that most of the time I don’t have a real alternative. Starting at the bottom (describing the low level functions) feels too dispersive especially with FP (compared to OO).
Moving away from Noir - Noir Deprecated Noir is at the moment the framework of choice to create web applications in Clojure. So it must have been an hard decision for the author first and the actual maintainer to abandon it. The fact is, Noir won’t be abandoned, it is just that Compojure is going to receive some re-newed love. I think it demonstrates maturity in the Clojure community: Noir was necessary at the time when to avoid to write a lot of boiler plate cod with Compojure alone, but Noir itself is not a lot more than a set of selected dependencies for ring/compojure. For this reason the actual project lead decided to split https://github.com/noir-clojure/lib-noir out of Noir, which is exactly that selection of libraries that you can now use on top of Compojure alone.
clojure-liberator/liberator · GitHub Liberator is a Compojure based framework to create REST services. It contains several abstractions to deal with resources and typical response handlers. Another key component of Liberator are “decisions” described as a way to limit or describe what a resource can do (like which http methods are accepted, which mime types and so on). It comes with an example project and some good recommendation (apparently it’s powering Datomic REST APIs).
nathanmarz/storm-deploy · GitHub Storm-deploy makes dead simple to deploy Storm clusters on Amazon services. It’s based on Pallet, which is based on JClouds. A good example of layering of abstractions to achieve the desired result and also an example of the endless freedom to drive existent Java libraries from Clojure. Storm-deploy requires to set a couple of configuration files. It’s actually more complicated to understand which AWS are required in the configuration file. If you get lost, this is a good guide: http://alestic.com/2009/11/ec2-credentials. Also, if you’re already on Leiningen 2, you need to patch the project.clj to work correctly. There is a pull request for that, so in the meanwhile you can replace project.clj with the conent of https://github.com/travis/storm-deploy/blob/57247084bb69fe0e08db76b23d0e7c6bc30dc031/project.clj
A Lazy Sequence: The Clojure web stack and the CRUD stack I don’t necessarily agree that Clojure doesn’t need an opinionated and convention-over-config web stack a-la Rails. Rails is also responsible for popularising Ruby and the entire Ruby ecosystem. Why the Clojure community wouldn’t want something like that? I do agree that not having a Rails like web stack gives flexibility and brings modularisation in web development, but those are not strong enough reasons not to work toward a common web stack targeted at a specific class of applications. The reason this still needs to happen is that we haven’t found our DHH yet.