Live data from Hacker News

Clojure Implemented in Pure Python

github.com

11–20 of 56 posts

Re: Clojure Implemented in Pure Python

#11
I cloned the Clojure-Py repo, installed it, but it didn't run (OS X 10.7.2, Python 2.7.1). I am no Python guy so I can't easily debug the problem at the moment.

I'm pretty excited about this though. I am a veteran Java developer but am tired of being tied to the JVM. Not everyone needs the interop as not everyone is developing in Java/JVM language/platform. I am also geeked about the future of ClojureScript, but not too sure I care much for it in the browser. There is just way too much of a disconnect with everything that is already out there. But, running Clojure on Node seems like a great solution.

I'd like to see more of Clojure written in Clojure someday (sooner than later). Those darned Java exceptions are impossible to decipher in the Clojure context, since there is no context being printed! If you've done even the tiniest of Clojure development, you will know what I am talking about. What we really need first is to see is Clojure's persistent data structures implemented in Clojure, rather than Java (or C#). It would be nice to have this code portable across runtimes (CLR, JVM, Python and perhaps a JavaScript interpreter).

I've been to both Clojure Conj (east coast) and am very excited about Clojure. So, the more ways you can execute Clojure the better (perhaps that will help getting Clojure written in Clojure).

Re: Clojure Implemented in Pure Python

#12

Er, what about Java interop? The notions of atoms, agents and refs? How are you going to translate these into "pure Python"?

CLR Clojure doesn't have Java interop either. Neither does clojurescript. I don't think its a requirement for a Clojure implementation. Atoms, refs and agents seem like an integral part of the Clojure language however.

I have to admit I'm not hip to all the newfangled doings with alternative Clojure targets. To me though java interop is one of the core differentiators for Clojure from other langs aside from its lispness. But, you're right, it's not required.

Re: Clojure Implemented in Pure Python

#13

Er, what about Java interop? The notions of atoms, agents and refs? How are you going to translate these into "pure Python"?

CLR Clojure doesn't have Java interop either. Neither does clojurescript. I don't think its a requirement for a Clojure implementation. Atoms, refs and agents seem like an integral part of the Clojure language however.

There's absolutely nothing stopping us from implementing atoms, refs, and agents on clojure-py. Sure, the GIL won't help at all, but PyPy is working hard to fix that.

Re: Clojure Implemented in Pure Python

#14
post #7

That looks nice. I have to ask: Clojure on the JVM is fast: can a PyPy runtime really compete after Hotspot has a chance to optimize?

All VM JITs compile to statically-typed machine code, so it's doubtful that building a VM from the ground up for dynamic code is going to yield major performance improvements. There are some enhancements that give VM-level visibility into dynamic invokation (like INVOKEDYNAMIC in JVM 7), but this has a relatively small performance impact on real-world codebases. In addition, the modern JVM is a sophisticated, highly-…

This is not true at all. PyPy implements a tracing jit that compiles specific loops for each set of types run through the interpreter. This means it is actually possible to have Python code that runs faster than C code in some rare cases: http://morepypy.blogspot.com/2011/07/realtime-image-processi...

Re: Clojure Implemented in Pure Python

#15
post #14
post #7

Earlier quoted context omitted.

All VM JITs compile to statically-typed machine code, so it's doubtful that building a VM from the ground up for dynamic code is going to yield major performance improvements. There are some enhancements that give VM-level visibility into dynamic invokation (like INVOKEDYNAMIC in JVM 7), but this has a relatively small performance impact on real-world codebases. In addition, the modern JVM is a sophisticated, highly-…

This is not true at all. PyPy implements a tracing jit that compiles specific loops for each set of types run through the interpreter. This means it is actually possible to have Python code that runs faster than C code in some rare cases: http://morepypy.blogspot.com/2011/07/realtime-image-processi...

Proving that there are cases where it's faster than C doesn't prove that it's faster than the JVM ;) There are plenty of cases where JVM code will be faster than C too...

Re: Clojure Implemented in Pure Python

#16
post #13

Earlier quoted context omitted.

CLR Clojure doesn't have Java interop either. Neither does clojurescript. I don't think its a requirement for a Clojure implementation. Atoms, refs and agents seem like an integral part of the Clojure language however.

There's absolutely nothing stopping us from implementing atoms, refs, and agents on clojure-py. Sure, the GIL won't help at all, but PyPy is working hard to fix that.

Is this a hobby project or are you aiming toward getting adoption? I will confess that I don't understand the point. If we accept the Church-Turing thesis then there's no reason that by the time you catch up to Clojure's performance on the JVM it will have been optimized beyond the measurement you made. The only real guarantee you can make is that you will have added an abstraction layer to Python.

While I definitely think this is a cool project, when I think about using it in production it strikes me as more Sisyphus than Prometheus.

Re: Clojure Implemented in Pure Python

#17
Here's a quick benchmark on my machine (a EeePC 1001HE). I used reduce1 with clojure-py because there doesn't seem to be a reduce BIF. I don't know if that effected this benchmark any:

Python:

    (time (reduce1 + (range 100000)))
    Elapsed time: 3882.57193565 msecs
    4999950000
PyPy:

    user=> (time (reduce1 + (range 100000)))
    Elapsed time: 259.984970093 msecs
    4999950000
Clojure via Java Hotspot:

    user=> (time (reduce + (range 100000)))
    "Elapsed time: 75.35225 msecs"
    4999950000

Re: Clojure Implemented in Pure Python

#18
post #13

Earlier quoted context omitted.

There's absolutely nothing stopping us from implementing atoms, refs, and agents on clojure-py. Sure, the GIL won't help at all, but PyPy is working hard to fix that.

Is this a hobby project or are you aiming toward getting adoption? I will confess that I don't understand the point. If we accept the Church-Turing thesis then there's no reason that by the time you catch up to Clojure's performance on the JVM it will have been optimized beyond the measurement you made. The only real guarantee you can make is that you will have added an abstraction layer to Python. While I definitely…

First of all, it should be mentioned, that this is not an abstraction layer. Clojure-py functions are actual Python functions (not classes as they are on the JVM). This means that the speed of clojure-py is almost exactly the same as python code.

Secondly, there is some benifit to not having to worry about static typing in a dynamic language. Anyone want to explain how to read a binary file in Clojure? Here's a hint, it takes the use of FileInputStream, DataInputStream. In clojure-py it's as simple as (py/open "foo.bin" "r").

And thirdly, why are we writing a dynamic language on a static VM? Fast Clojure code on the JVM these days takes little hints. You have to tag parameters with ^Integer and ^Double to kick the compiler type inference into gear. None of this is required on a dynamic VM. In fact, it's completely pointless.

Re: Clojure Implemented in Pure Python

#19

Here's a quick benchmark on my machine (a EeePC 1001HE). I used reduce1 with clojure-py because there doesn't seem to be a reduce BIF. I don't know if that effected this benchmark any: Python: (time (reduce1 + (range 100000))) Elapsed time: 3882.57193565 msecs 4999950000 PyPy: user=> (time (reduce1 + (range 100000))) Elapsed time: 259.984970093 msecs 4999950000 Clojure via Java Hotspot: user=> (time (reduce + (range…

Those numbers a re bit small to get a full view of the way the pypy jit works:

  user=> (time (reduce1 + (range 100000)))
  Elapsed time: 903.011083603 msecs
  4999950000
  user=> (time (reduce1 + (range 1000000)))
  Elapsed time: 777.748823166 msecs
  499999500000
  user=> (time (reduce1 + (range 10000000)))
  Elapsed time: 8764.57095146 msecs
  49999995000000
  user=>

  Clojure via hotspot:
  user=> (time (reduce + (range 100000)))
  "Elapsed time: 174.768593 msecs"
  4999950000
  user=> (time (reduce + (range 1000000)))
  "Elapsed time: 267.60421 msecs"
  499999500000
  user=> (time (reduce + (range 10000000)))
  "Elapsed time: 1131.77367 msecs"
  49999995000000
  user=>
But yes, we still have some room for improvement.

Re: Clojure Implemented in Pure Python

#20
post #18

Earlier quoted context omitted.

Is this a hobby project or are you aiming toward getting adoption? I will confess that I don't understand the point. If we accept the Church-Turing thesis then there's no reason that by the time you catch up to Clojure's performance on the JVM it will have been optimized beyond the measurement you made. The only real guarantee you can make is that you will have added an abstraction layer to Python. While I definitely…

First of all, it should be mentioned, that this is not an abstraction layer. Clojure-py functions are actual Python functions (not classes as they are on the JVM). This means that the speed of clojure-py is almost exactly the same as python code. Secondly, there is some benifit to not having to worry about static typing in a dynamic language. Anyone want to explain how to read a binary file in Clojure? Here's a hint,…

[deleted]
Post reply on HN