Clojure roundup

January 10, 2009

In the last few weeks, there’s been a fair amount of Clojure news and activity here in our study group. Here are some links to things we’ve been watching.

  • A new language release. On December 17th, Rich “cut a new release” of the language. This should bring the offical release up to date enough for most people, although you’re still advised to check out the latest from Subversion, especially a few months go by without another official release
  • Streams vs. sequences. A lively discussion about the right implementation(s) of laziness and the role of caching in Clojure’s sequences. There is a move afoot to add true streams to Clojure, although the ramifications of such an addition are uncertain.
  • Compojure. Yes, Clojure has its own web framework now, and it looks pretty smart. Its syntax is inspired by Ruby’s Sinatra, it interfaces with Jetty, and it lets you write HTML in a vector-tree fashion that looks odd but probably saves the experienced user lots of keystrokes. Eric Levigne has written some posts about using Compojure to run a website.
  • Paul’s article on bean and Java interop. A nice tip on making it easier (and more Clojure-ish) to work with Java libraries.
  • Luke’s Markov chain generator and Michael’s post about it. Luke wrote a cool program that generates an output text from the pieces of an input text and uses pattern analysis and probability to mimic the style of the input text. Your humble blogger responded with a post examining the workings of the program and suggesting ways to build on it. This could become a group project.

That isn’t everything that happened in Clojure lately, not by a long shot, so feel free to comment to ad your own observations. Also, consider joining our study group list (link in the column to the right) to contribute. You don’t have to be in DC or come to meetings–we’d love to hear from you.


Code walkthrough in Hickey presentation

December 6, 2008

**Update 12/11/2008: In the original post, I claimed the code from Hickey’s presentation needed to be updated to the latest version of Clojure. Wrong. The code wasn’t running for me because I didn’t have the de facto latest version, which is built from subversion. I’ve edited the post to reflect this. **

Hickey’s presentation to the Western Massachusettes Developers Group is primarily about Concurrency. The first half covers similar topics to his other presentations (including the For Lispers presentation). But about halfway through the talk, at 1:16:00, he begins a walkthrough of a program he wrote simulating an ant colony. I really recommend following this. It’s helped me a lot.

So go view the video:

Get the code for the simulation too, from the link on the Blip page. As of this posting, you’ll need to build clojure from subversion to make the code work. If you’re using the latest official release, from September 16, you’ll need to use a copy of the code I made: http://groups.google.com/group/clojure-study-dc/web/ants.clj.

The key difference is in the java interop syntax. The latest version of clojure uses a dot before a method call in many circumstances, whereas the official release does not. In other words:

(doto g
    (.setColor c) ;; current syntax, with dot
    ...

vs.

(doto g
    (setColor c) ;; official release syntax, no dot.
    ...

If you run current Clojure code using the official release, you’ll see a lot of errors like these:

java.lang.IllegalArgumentException: No matching method found: 
  .setPreferredSize for class clojure.lang.Proxy__2845

The walkthrough takes about an hour. Give it a try.