An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Learning Clojure

May 3, 2010 ·

This past weekend, I attended Amit Rathore's ProClojure boot camp to learn the Clojure programming language. Back in the 80's, I had quite a bit of exposure to Lisp but haven't had cause to use those techniques since. Clojure is essentially Lisp reinvented for the JVM. I'm already using Scala which blends both OOP and Functional Programming styles - and I've dabbled in Erlang and Haskell over the last few years.

The day started early (I'm not a morning person at the best of times but needing to be in Mountain View around 8am on a Saturday was hard!) and Amit explained that we would be work in pairs all day and to emphasize that he gave us five minutes to get to know our partner well enough to introduce them to the group, rather than us each introducing ourselves. A very nice touch! The plan for the day was one person drives in the morning and then you switch for the afternoon. The course was very much hands on so the pairing really helped us focus on programming together and learning from each other, as well as learning from Amit!

In the morning we focused on basics and building versions of some of the built-in functions so that we could understand the core techniques. In the afternoon we focused on more advanced techniques, including quite a bit of time on macros (which allow you to build sophisticated Domain Specific Languages on top of Clojure).

I really enjoyed the day. Amit (and his colleague Siva) were excellent hosts at Runa (who use Clojure in production). Some of the material used in the course was drawn from Amit's book: Clojure in Action (which I bought as soon as I got home and I'm thoroughly enjoying).

As I've said several times in the past, I highly recommend learning other languages to give you a new perspective on the language you use every day for work (even better if you can use multiple languages in your day job!).

I've decided to post the two files I created during the course, which are a mix of Clojure functions and notes that I took, so that you can get a sense of the language:

  • exercises.clj - general exercises from the morning that focused on basic Clojure
  • expenses.clj - more advanced examples (several focusing on filtering an expense report)

I hope you enjoy the examples and find Clojure to be intriguing!

And just in case you think Clojure is too different to CFML and too 'niche', bear in mind that CFML also treats functions as first class citizens that you can pass around and call in different contexts - and I've shown some functional programming examples in the past on my blog with CFML!

Tags: clojure · coldfusion · programming

5 responses

  • 1 Elliott Sprehn // May 4, 2010 at 1:58 AM

    I looked into Clojure not long ago and it's pretty impressive for being so recent. I've always used SBCL or GNU CLISP when I've worked with Lisp. The only thing I found annoying in Clojure was the proliferation of arrays. I completely understand the performance reasons with the JVM, but syntactically having tons of square brackets mixed in with the parens really detracts from the elegance. On the other hand it did look like they cleaned up a lot of the macro syntax bloat which was very cool.

    Have you looked at OCaml? That's my favorite language of the functional persuasion. :)
  • 2 Sean Corfield // May 4, 2010 at 9:48 AM

    I hadn't looked at OCaml before but it looks like it is entirely standalone because it doesn't target the JVM. That's also the downside of Erlang for me.

    OCaml looks a lot like SURE which was the functional language I designed and implemented in the mid-80's for my PhD research - but then it's also inspired by ML :)
  • 3 Brian Panulla // May 27, 2010 at 10:04 AM

    I caught a talk on Clojure at Portland Code Camp last weekend.... mind-altering stuff. I did see a little echo of ColdFusion in how the symbols get evaluated... on the surface it reminded me of CF's IIF/DE cul-de-sac.
  • 4 Sean Corfield // May 27, 2010 at 11:22 AM

    Clojure doesn't have any of the limitations of IIF() in CFML but I understand why you'd see a similarity. And, yeah, Clojure is pretty mind-altering - especially when you get into macros that can transform the code automatically before processing, themselves using the full power of the Clojure language. It allows for some very powerful DSLs (Domain Specific Languages).
  • 5 nickik // Sep 27, 2010 at 2:36 PM

    @Elliott Sprehn I can see how it is unusual but I think its a really elegante way to use all those diffrente data structures. In macros people use (vec ....) witch works to if you dont like the [] and '().

    @Sean Corfield now there is erjang check it out, i don't know how far the are but I think the are pretty far.