views:

335

answers:

3
+9  Q: 

CLOS for Clojure?

Does there exist anything like CLOS (Common Lisp Object System) for Clojure? If there isn't, how hard would it be to write one? Thanks in advance.

-- Eric Grindt

+6  A: 

Have you considered Clojure's data types (especially defrecord), protocols, and multimethods? All three will always be more idiomatic within Clojure than a port of CLOS on top of these mechanisms.

Chas Emerick
Then again, if we all listened when somebody said "don't do this, it's dumb", Steve Russell might have listened to John McCarthy and never hand-compiled his `eval`, and we might never have had Lisp on a computer at all. Thus began a long history of Lisp hackers who had no respect for what somebody else said was the right thing to do! So I say, go for it, port CLOS to Clojure, and see what happens. Really, what's the worst that could happen? :-)
Ken
I'm not saying, "don't reimplement CLOS". I'm just saying that the facilities provided and supported by the core of a language should at least be considered for a given use before attempting to treat a horse like a cow, as it were. Now, if one is brave (/foolish?), all sorts of object systems could be built on top of those core facilities: certainly CLOS if one were so motivated, and likely far more advanced paths as well.
Chas Emerick
+4  A: 

Clojure does not have CLOS and doesn't want CLOS but you could implement it.

Clojure wants to be immutable so to have mutible OO would be kind of stupid but you can have a kind of OO.

With these three things you should be able to fulfill all your needs but most of the times its best to just use normal functions and the standard datastructures.

nickik
+7  A: 

Clojure itself doesn't have an object system, for two reasons:

  1. Clojure is specifically designed to be hosted on an object-oriented platform and it then simply absorbs the underlying platform's object system. I.e. ClojureJVM has the JVM object system, ClojureCLR has the CLI object system, ClojureScript has the ECMAScript object system, and so on.
  2. Rich Hickey hates objects.

But, you can obviously implement an object system in Clojure. Clojure is, after all, Turing-complete.

Mikel Evins is working on a new approach to OO which he calls Categories. He has implementations for several Lisps, including Clojure (although not all the ports are guaranteed to be up-to-date all the time).

Categories is slowly being subsumed by Bard, a new Lisp dialect that Mikel is designing, which has Categories built in. (Which then, in turn, may become the implementation language for Closos, an idea Mikel had for how to design an operating system.)

Jörg W Mittag