What is your opinion on Clojure? [closed]
Asked Answered
C

10

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?

Concerto answered 16/1, 2009 at 19:25 Comment(0)
R
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.
Recoup answered 18/2, 2009 at 11:24 Comment(1)
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!"Halsy
M
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.

Millican answered 20/3, 2009 at 10:54 Comment(2)
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.Revulsion
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.Millican
T
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

Thirtytwo answered 7/10, 2009 at 9:20 Comment(5)
Have you tried Armed Bear Common Lisp, full blown CL implementation on the JVM. It's development seems pretty active.Recoup
+1 for the "you can safely assume your problem will work everywhere" part. Not sure if it's a typo or intentional but it made me laugh.Foehn
@NikolaKolev I had a problem so I decided to use Clojure. Now I have a (problem)Shaun
@Tom or maybe (have I problem)Rosena
@CodeMonkey1 haha, true :) I had a problem so I decided to use Clojure. Now (have I problem)Shaun
O
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.

Ornamented answered 16/1, 2009 at 19:32 Comment(5)
Not all Lisp dialects are equally powerful. Unless by A being at least as powerful as B you mean that B is implementable in A. In which case all Turing-complete programming languages are equally powerful, and the question becomes nonsensical.Millican
The old well trained flock of pigeons argument.Ornamented
I think he just felt like typing something, because his comment was rather redundant.Rollerskate
@Rayne: That's because it was implemented in English.Motherofpearl
Clojure hasn't got reader macros... It might be useful sometimes though.Barbarbarbara
I
14

I think the name is clever.

Indigoid answered 16/1, 2009 at 19:30 Comment(2)
Yet tricky to pronounce.Orogeny
Better than "Erjang" on the ears to be sureUnmade
I
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.

Imprisonment answered 16/1, 2009 at 19:49 Comment(0)
H
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?

Halsy answered 12/6, 2009 at 18:15 Comment(0)
A
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.

Allveta answered 14/10, 2009 at 14:22 Comment(0)
C
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. "

Concerto answered 16/1, 2009 at 20:17 Comment(5)
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.Obese
so in the Scheme example u're saying that because variables of the object are in the same namespace as its methods?Concerto
yes. (Clojure avoids Lisp-1's problem with symbol capture in macros by qualifying all symbols with their namespace: en.wikipedia.org/wiki/Clojure#Macros)Greenwald
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.Fayfayal
thank you very much for the insightful answersConcerto
S
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. :)

Sancho answered 19/2, 2009 at 10:45 Comment(2)
I don't see how the syntax is harmed by Java APIs. :\Rollerskate
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.Afloat

© 2022 - 2024 — McMap. All rights reserved.