Javascript for clojure

I know ClojureScript - the ability to compile clojure code in javascript, but is it possible to do the opposite, take some subset of javascript code and translate it back to clojure?

+8
javascript lisp clojure
source share
5 answers

Yes, although that would not make sense.

Clojure -> JavaScript makes sense because:

  • JavaScript is the only suitable target language for a wide class of web applications.
  • This allows you to effectively use the Google Closure compiler to optimize the entire program.
  • Clojure is a great source language because of its macro features and great support for defining expressive DSLs.

Clojure would be a strange choice for the target language - if you want to run on the JVM platform, it would be more natural to focus directly on Java bytecode.

JavaScript would also be a weird choice for compiling Clojure source code - if you want to use Clojure code, why would you just write Clojure directly? In particular, using (a possible subset of) JavaScript will not give you easy access to all the features that make Clojure really attractive (lazy functional programming, concurrency support, macro macro programming, persistent data structures, etc.)

+4
source share

Yes, it is definitely a possible and very effective idea. In fact, you could use the Rhino Javascript compiler to convert Javascript classes to Java and then mount something to call Java classes from Clojure. You do not get the source code, but you can use the libraries in the Clojure code.

+3
source share

I just happened to come across a Common Lisp JavaScript translator called CL-JavaScript .

+3
source share

Yes, you can translate JavaScript into Clojure. Like other dialects in the Lisp family, Clojure is well suited for creating parsers and compilers for other languages.

+1
source share

You can only do this with Chlorinejs, a subset of Clojure that has a lot to do with javascript. https://github.com/chlorinejs/chlorine/wiki https://github.com/chlorinejs/chloride

+1
source share

All Articles