Clojure & Python, Side by Side
tin.nu
tin.nu
But that's not how I (nor, I imagine, any experienced Lisper) would do it. Lisp programmers are not afraid to write compilers in Lisp targeting Lisp. This is not something a Python programmer would consider doing.
I would implement Dan Friedman et al's Scheme constraint solver (cKanren) in Clojure (which can be done in a few hours) so I could solve all sorts of problems, not just Sudoku, in 80 lines of code instead of 200 with very good performance.
Given the addition of core.logic into Clojure 1.3.0, one could even skip the implementation of cKanren. Although to be honest I'm not altogether sure how core.logic measures up to cKanren.
http://www.nevercertain.com/2011/08/17/scala-ruby-rosetta.ht...
I know python well enough to hack my way around it. I'm probably missing something, but now I have to ask: what would be the point in me learning clojure?
I guess all I'm saying is "convince me!" :) I'm all ears.
I think what Clojure can offer on top of that is macros, the advantages of which are really only evident on bigger or harder problems.
Why Functional Programming Matters: http://www.cs.utexas.edu/~shmat/courses/cs345/whyfp.pdf
Out of the Tar Pit: http://web.mac.com/ben_moseley/frp/paper-v1_01.pdf
Simple Made Easy: http://www.infoq.com/presentations/Simple-Made-Easy
Clojure's design goals combine some deep ideas about identity, state and time together and includes data structures and a concurrency API that supports these goals. It's going to be hard for anyone to just convince you in a comment like this, and even if they could, I'm not the one to do it as I'm a Clojure noob.
You should read this essay http://clojure.org/state and watch this talk http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hic....
I think you will find that Clojure is pretty interesting, even if you don't start using it right away. I apologize for just throwing you links, but I can't do it justice, and Rich Hickey is a great lecturer, so you'll get more from his stuff.
Its not so much about brevity or productivity as it is about correctness. Functional programming and immutable data makes it easier to reason about code and to prevent bugs/errors, especially in the context of concurrent/multicore code.
Anyways, YMMV. All I got to do once was set my Django application to run on Jython, and that was relatively painless.
Personally, I want to use a language implementation that will be around and (well!) supported for many years.
Clojure has a focus on functional programming, immutable data[1] and the sequence abstraction[2].
Clojure is a Lisp and has most[3] of the super-powerful metaprogramming facilities that you would expect from a Lisp. This means you can, with enough effort, mold the language to suit your needs, even turning it into a completely different language should you wish to do so.
Clojure is not object oriented, though it does allow you to instantiate and create Java objects for the purpose of interacting with Java libraries. Clojure does support OO-like code through its Records/Protocol system.
Clojure has out-of-the-box support for multimethods.
Clojure runs on the JVM and therefore has access to the many many libraries written in Java or other JVM languages.
Pure Clojure code is, as far as I can tell, higher performance than pure CPython code.
PS: Just for the record, I love Python and use it a lot (and have actually been out of touch with Clojure for almost nine months now, sadly). The above are reasons why you may want to learn Clojure - not reasons to drop Python.
[1] The benefits on pure-functional code and immutable data are that it makes concurrency easier and safer and that it makes code easier to reason about as you do not need to consider that 1) side-effects are happening behind your back and 2) the data is being changed elsewhere (which is also why it makes concurrency easier).
[2] Similar idea to Pythons iterables, except IMHO Clojure's sequences are much more a part of the core language than iterables in Python, in that in Clojure most things are sequences, while in Python this isn't the case (though a lot of things are iterables).
[3] I say most because Clojure does not have reader macros
Not so here; the author mentions that the Python version is faster (in his blog post).
How does it compare with Scala?
Coming from Ruby this approach was a bit mind-boggling at first, but even with my fairly limited Clojure exposure (or should that be expojure?) I've come to appreciate how easy pure functions are to test and to reason about.
It's not pretty and side-by-side, but it's fascinating.
Just an amateur opinion although.
If I want fast performance I code in C or other low level language. Sorry Clojure community, I'm not drinking the kool aid this time.
For me, Clojure is great because it allows you to build powerful abstractions and has some interesting concurrency constructs, while running on the JVM and making it easy to interoperate with Java code. Of course, being a Lisp, it uses Lisp syntax.
Most of us just get stuff done using Clojure, quickly, getting concise and most importantly — correct code, even in massively multithreaded applications.