Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

November 2008
Sun Mon Tue Wed Thu Fri Sat
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Oct  Dec

Clojure is about programming to abstractions

Saturday, November 8, 2008

I came across a nice inheritance graph for Clojure in the files section of the Clojure Google Group. It was created by Chouser and the source code for generating it is here (on my Mac, I just had to tweak the paths in the "srcpath" and "png" defs). Very nice way to visualize the relationships:

clojure.lang visualization

As Rich Hickey said:

"Clojure is about programming to abstractions, among other things. So you don't want to rely on the exact concrete types of things, but rather the interfaces they implement.

There are many useful interfaces in Clojure. Chouser put together a nice visualization:
http://clojure.googlegroups.com/web/chart.png

If you use class as a dispatch function in a multimethod, you can use an interface, like IPersistentMap, as a dispatch value and it will

match all classes that extend IPersistentMap, since multimethod dispatch uses isa?

There are also predicates that correspond to most of the interfaces, like map?, list?, vector?, sorted? etc, all of which internally use (instance? someInterface x). The aforementioned chart includes the corresponding predicates.

In general, it is bad style to use class equality, as in (= (class this) (class that)) - better to use instance? or isa?. "

emacs Copyright © 2008 by Bill Clementson