Clojure-Scheme
github.com
github.com
I'm very happy to see the multi-platform vision of Clojure becoming closer to reality. I'm not in the "write once, run everywhere" camp. That goal is a bit ridiculous, but the choice of VM and the choice of language should be independent decisions. I like Erlang's VM a lot, but the language itself is not very nice. When writing iPhone code, I don't want to be forced to use Objective C.
If not, usually it's not too difficult to only wrap the calls that you need. There are also methods for automatically generating FFIs, although that only works with certain APIs.
Cocoa is definitely accessible from C. Objective-C is just a superset of C, so if you compile all the generated C files as Obj-C you can write any Cocoa code you want.
You can simply do this (the actual FFI call might be wrong, it's been a while):
(c-lambda (ptr) void "[___arg1 sendThisMessage:1];")
You can literally code Obj-C straight into it.
There has just recently been a port of the iOS Gambit repl to Android (using NDK and JNI I think)--I'm looking to try that out next.
http://apps.keithflower.org/?page_id=152
I'm about to release an update to match the iOS version accompanying Gambit v4.6.5 (as close as I can get).
(define hello-world (lambda () (display "Hello world!") (newline)))
(hello-world)
And it compiles to 5mb. Is this the standard library? Can I expect to more complicated applications to not balloon up in size?One thing not mentioned was the memory use: I bet that the compiled to Gambit-c and then to a native executable code uses a tiny fraction of the memory of Clojure running in the JVM. That can be important for some applications.
Although: 1.1 seconds for clojure repl, 0.8 seconds for gsc-compiled version. That's actually less of a difference in speed than I'd expected. Not being very familiar with ClojureScript, is this clojure repl running in the JVM or in V8?
Edit: on that note, it'd be interesting to compare timing after compiling with Stalin.
It says "Clojure" Repl, and in that case it would be running directly on the JVM.
I timed the fib(36) function from within a clojurescript repl inside a clojure jvm repl, and it returned in 86 seconds.
Then I timed the generated js function in a Chrome console with a not-so-minor modification so it would compile, it returned in 13 seconds. The modification in question was inlining the generated cljs.core.truth_(predicate) javascript function.
The orders of magnitude don't lie though - for what it's worth, a recursive fibonacci implementation in plain java returns in about 125ms (and depending on jvm warm-up, an array-backed computation is a merry jog of 50 to 300µs, but that's completely off-topic)
I have yet to setup gambit and clone the clojure-scheme project. I'm really curious though, I like these 800ms that the author advertises.
Does anyone know of a collection of Clojure benchmarks that stress various aspects of the runtime? (garbage collection, immutable update, polymorphism, etc.)
Clojure is probably bringing in some start-up overhead. If it is indeed just a start-up overhead, it would be less of a problem.
Crazy stuff.
also, i wonder how much of clojure is lost through not being able to call down to java?
For command-line programs, this could be pretty rad, as is ClojureScript on V8. It's also just cool :)