51

What do you guys think about Clojure? I'm thinking of learning it next, currently using Erlang and in general happy with it except the records fiasco... Is Clojure as powerful as LISP?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
deepblue
  • 8,426
  • 13
  • 48
  • 60

10 Answers10

133

Consider learning it. If for no other reason then because you can actually use it in a real project.

You : Can I use this small Java library called Clojure?
Boss: Why do you need it?
You : For some concurrency improvements.
Boss: Ok.
Marko
  • 30,263
  • 18
  • 74
  • 108
  • 24
    I asked righ hickey about this post at a bar after Java One and i paraphrase his response "sure sneak Clojure in any way you can!" – Arthur Ulfeldt Jun 12 '09 at 18:09
26

What you're refering to by Lisp-1 vs Lisp-2 is the question of whether functions and variables share the same name space. In Lisp-1 Lisps, like Scheme and Clojure, they do. In Lisp-2 Lisps, like Common Lisp, they do not. This is mostly a matter of taste and/or convenience - it doesn't affect the power of the programming language.

As an example, in Clojure you can do this:

(defn my-apply [func arg1 arg2]
  (func arg1 arg2))

This is a function that takes a function and two values and applies the function to the values. For example:

user=> (my-apply + 1 2)
3

In Common Lisp, you'd have to write this as

(defun my-apply (func arg1 arg2)
  (funcall func arg1 arg2))

The reason you need "funcall" is that, since "func" is in the name space of variables, you cannot directly use it as a function, like you can in Clojure, which does not make this distinction. So you have to tell Common Lisp "please interpret this variable as a function and call it with these arguments". Another consequence of this is that to get the same result you must call "my-apply" like this:

=> (my-apply #'+ 1 2)
3

Here the problem is reversed: "+" is a function, but you want to pass it as a variable, so you have to "convert" it. "#'+" is short for "(function +)", btw.

Mark Probst
  • 7,107
  • 7
  • 40
  • 42
  • 3
    The interesting consequence: in Common Lisp as a Lisp-2 you know that in (foo 2) FOO will be a function. There is no way to bring, say, a number in function space. This means, you never have to check this at runtime other than in FUNCALL. – Rainer Joswig Mar 20 '09 at 11:18
  • 5
    Certainly. But then again, Clojure makes maps and vectors callable. I'm not saying it's terribly useful, just that there might be some point to it. – Mark Probst Mar 20 '09 at 15:18
22

I use Clojure and not CL because:

  • It communicates well with Java, so I can outsource my coding
  • It has access to the zillions of java libraries that do all sorts of things, including Swing and Weka
  • Since it runs on the JVM, you can more safely assume that your problem will work everywhere
  • If you can show the same libraries being used with much less code, you can convert Java programmers to the lambda way
  • And, most importantly, I don't get tied to Emacs

:wq

konr
  • 1,173
  • 12
  • 26
16

Clojure is a dialect of LISP so, yes, it's as powerful as LISP.

For no other reason than we now have a good LISP tool for the JVM I like this language.

Allain Lalonde
  • 91,574
  • 70
  • 187
  • 238
14

I think the name is clever.

Bill Echo
  • 308
  • 1
  • 6
14

"Clojure has the potential to do for concurrency-oriented programming what Java did for object-oriented programming a decade ago: make it simpler to do properly using a language (or, in Clojure’s case, a “language environment”) that is similar to what programmers are already used to. " -- Bill Clementson

And people, LISP consists of a family of programming languages. There are Lisp dialects like Common Lisp and Clojure. And on top of that, there are many implementations of Common Lisp or Scheme.

Berlin Brown
  • 11,504
  • 37
  • 135
  • 203
5

Clojure is a Lisp-1, yes. Think of it as a nicer Common Lisp without all the historical baggage. It also has several modern concurrency features like STM and Agents (they decided not to implement Erlang's Actors model). The advantage of running on the JVM is simple- there are already SO many libraries written for it (mostly in Java).

Clojure in Clojure is an ongoing effort to rewrite the Clojure compiler in Clojure, to make it more portable and maintainable. Apart from core.clj, most of Clojure is written in Java presently. After this move, it'll be possible to port it to a LOT of VMs, including Parrot.

artagnon
  • 3,609
  • 3
  • 23
  • 26
5

I used Erlang at work for coordinated network load testing and it was perfect for that because the problem was well within Erlang's "sweet spot" of "doing distributed communication oriented software correctly". I find Clojure MUCH better for code that needs to do something complex on a single box with several threads (this is a more common scenario).

You are ahead of the curve because you know Erlang and this will help you spot the problems in which it really shines. What do you thing Clojures real "sweet spot" is?

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
3

what I mean by "is Clojure as powerful as LISP" is that i read someplace here on stackoverflow that Common Lisp is lisp-2 and Clojure is lisp-1? (I could easly be rambling here)...

as far as concurrency is concerned I really like the Erlang story since its so easy to distribute apps by writing them in the Actor model

from the creator of Clojure at http://groups.google.com/group/clojure/browse_thread/thread/2a2b24ffef5d1631?pli=1

"Even with actors, Clojure will not yet have a distributed concurrency story, but I am considering just adopting Erlang's wholesale, using Jinterface for Clojure<->Clojure or even Clojure<->Erlang distributed processes. Maybe that will look like Termite when it is done. Stay tuned. "

Rayne
  • 31,473
  • 17
  • 86
  • 101
deepblue
  • 8,426
  • 13
  • 48
  • 60
  • 3
    Lisp-1 vs. Lisp-2 refers to whether functions live in the same namespace as everything else, or whether functions have their own namespace. It doesn't have anything to do with power. It means Scheme has to use "lst" as a variable name instead of "list", and CL has to use "funcall" a lot. – Brian Carper Jan 16 '09 at 20:23
  • so in the Scheme example u're saying that because variables of the object are in the same namespace as its methods? – deepblue Jan 16 '09 at 20:58
  • 1
    yes. (Clojure avoids Lisp-1's problem with symbol capture in macros by qualifying all symbols with their namespace: http://en.wikipedia.org/wiki/Clojure#Macros) – Nathan Shively-Sanders Jan 16 '09 at 22:20
  • 1
    Seconded: Clojure's nice use of namespaces largely solves the issues with a lisp-1. None: you probably don't care too much about lisp-1 vs. lisp-2 unless you're writing a lot of macros. That said, macros are greatly simplified this way. – Chris Feb 20 '09 at 19:11
  • thank you very much for the insightful answers – deepblue Feb 20 '09 at 21:44
3

I like Common Lisp better than Clojure because the syntax is more regular and it's not tied to the horrible (IMHO) Java APIs.

For Common Lisp I also have the choice between several excellent and well-tested implementations and a mature standard to rely on.

But if I had to use Java for a job then I would definitely consider using Clojure. :)

Leslie P. Polzer
  • 2,998
  • 21
  • 18
  • I don't see how the syntax is harmed by Java APIs. :\ – Rayne May 01 '09 at 12:32
  • 4
    You don't have to use any Java APIs in Clojure if you don't want to. i.e. you can write great, functional, LISP code in Clojure without touching any of the Java interoperability features. On the other hand, there are many great Java libraries so I personally find this a big plus point of Clojure. – mikera Nov 02 '10 at 12:57