Take the 2-minute tour ×

I have been working recently with Clojure's types and records recently, and I was wondering if these are very new concepts, or are they inspired by the Common Lisp Object System?

share|improve this question
add comment

1 Answer

up vote 11 down vote accepted

I believe they are pretty much new innovations within Clojure.

CLOS is a fairly complex, fully featured object oriented system. It features various OOP techniques you often hear mentioned and which exist in other object oriented languages - multiple inheritance, dynamic dispatch, generic functions etc.

Clojure takes a different approach - types and records are much simpler than full OOP and are not intended to constitute a full OOP system. Rather, I understand that the design is motivated by:

  • The belief that many OOP techniques are actually harmful when building large systems - implementation inheritance for example
  • The opportunity to get maximum performance (i.e. the same as Java) for the most common case of polymorphism (i.e. single dispatch on type)
  • The desire to solve the "expression problem", which you can do in Clojure using deftype / defrecord together with protocols
  • The intent to make all records/types immutable in order to fit with the rest of Clojure's philosophy

If you want a traditional object oriented system like CLOS, it would be possible to build this in Clojure on on top of types and records. You can also use Java-style object orientation directly within Clojure. However I believe it's not usually recommended by Clojure experts - Clojure usually offers you different or better ways to solve the same problems.

In general - Clojure tends to provide you with "simple" tools that you can compose to solve the problem at hand, rather than prescribing a complex framework at any point. It's an interesting philosophy discussed at some length in this video by Stuart Halloway.

share|improve this answer
This is a good description overall, but I don't agree that CLOS is "fairly complex". I find it beautifully simple. TAOMP implemented it all in about 1000 LOC -- the only other object system I know of that's shorter is Smalltalk. Even the 'advanced' features of CLOS aren't so much 'complex' as "rather than make any limits, we kept it open, and declared it part of the standard interface so you can depend on it". You've got classes with slots, and generic functions and methods ... everything pretty much falls out of that. –  Ken Apr 18 '11 at 18:06
@Ken - that's fair, I certainly meant complex in the sense of "contains lots of features" rather than meaning to imply it was complicated/unmanageable :-) –  mikera Apr 19 '11 at 11:12
CLOS is traditional? What other system gives generic functions primacy like CLOS? Or even includes the concept of a generic function? –  Xach Apr 19 '11 at 19:00
add comment

Your Answer


