Clojure on JS VMs

33 views
Skip to first unread message

Timothy Baldridge

unread,
Mar 3, 2011, 9:56:44 AM3/3/11
to clo...@googlegroups.com
I know we have Scriptjure. But has there been any concentrated effort
to port Clojure to JS? This may sound odd, but personally I would love
to use Clojure in the browser. Scriptjure would work fairly well, but
from what I see, it doesn't support persistent maps and instead relies
on JS objects.

Timothy

--
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

Joost

unread,
Mar 3, 2011, 10:03:34 AM3/3/11
to Clojure
On Mar 3, 3:56 pm, Timothy Baldridge <tbaldri...@gmail.com> wrote:
> I know we have Scriptjure. But has there been any concentrated effort
> to port Clojure to JS? This may sound odd, but personally I would love
> to use Clojure in the browser. Scriptjure would work fairly well, but
> from what I see, it doesn't support persistent maps and instead relies
> on JS objects.

Not as far as I know. Scripture is extremely limited; it's only a lisp-
like wrapper on basic javascript that just happens to have names like
clojure's. For instance, there's not even "real" (if ....), (let ..),
no automatic returns etc.

Its possible to do a real port of clojure that sort of does the basics
right, but that would be a lot more involved than just translating
source code.

Joost.


James Reeves

unread,
Mar 3, 2011, 10:03:34 AM3/3/11
to clo...@googlegroups.com
On 3 March 2011 14:56, Timothy Baldridge <tbald...@gmail.com> wrote:
> I know we have Scriptjure. But has there been any concentrated effort
> to port Clojure to JS? This may sound odd, but personally I would love
> to use Clojure in the browser. Scriptjure would work fairly well, but
> from what I see, it doesn't support persistent maps and instead relies
> on JS objects.

Persistent maps would be pretty tricky to support in Javascript. I
don't think there's any way of supporting them that wouldn't result in
a significant performance impact, because you'd have to build them on
top of the native mutable maps.

- James

Chouser

unread,
Mar 3, 2011, 11:11:14 AM3/3/11
to clo...@googlegroups.com, Timothy Baldridge
On Thu, Mar 3, 2011 at 9:56 AM, Timothy Baldridge <tbald...@gmail.com> wrote:
> I know we have Scriptjure. But has there been any concentrated effort
> to port Clojure to JS? This may sound odd, but personally I would love
> to use Clojure in the browser. Scriptjure would work fairly well, but
> from what I see, it doesn't support persistent maps and instead relies
> on JS objects.

There has been, but it's extremely out of date at this point:

https://github.com/clojure/clojure-contrib/tree/master/clojurescript

That's a pre-1.0 version of Clojure that does indeed compile to
JavaScript. It supports persistent hash maps and vectors
(pre-transients), lazy sequences (actually, lazy-con, pre-chunking),
and most of the clojure.core functions. There's no attempt to support
Clojure's concurrency constructs, and it relies on the Java-based
compiler rather than having a port of the compiler itself to
JavaScript.

I gave up trying to hand-port all the features from the Java half of
Clojure's implementation over to JavaScript, with the hope that when
we eventually have clojure-in-clojure this task would be significantly
easier.

You can even try it out in a browser (doesn't work on Macs, I think):
http://clojurescript.n01se.net/

That loads the clojure-to-javascript compiler as a Java applet, after
which you can run Clojure commands in the browser, like:

(-> document .body)

or:

(set! (-> document .body .style .background) "orange")

I'm sorry it's too out of date to be of much real use now, but it does
show it's possible and hopefully has some tidbits that will be useful
in later implementations.

--Chouser
http://joyofclojure.com/

James Sofra

unread,
Mar 7, 2011, 5:22:00 AM3/7/11
to Clojure
This seems a little more up-to-date than clojurescript.

https://github.com/zkim/cljs

It is not complete (the author calls it clojure(ish)) but still seems
pretty nice.

-James S
Reply all
Reply to author
Forward
0 new messages