最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript to clojure - Stack Overflow

programmeradmin1浏览0评论

I am aware of ClojureScript - possibility to compile clojure code to javascript, but is it possible to do the reverse, take some subset of javascript code and translate it back to clojure?

I am aware of ClojureScript - possibility to compile clojure code to javascript, but is it possible to do the reverse, take some subset of javascript code and translate it back to clojure?

Share Improve this question edited Jul 22, 2011 at 15:55 Terje Norderhaug 3,68923 silver badges25 bronze badges asked Jul 22, 2011 at 9:41 JiriJiri 16.6k6 gold badges55 silver badges68 bronze badges 3
  • Doubt it, can't even find a JavaScript to LISP compiler, although you could always just write one. – Raynos Commented Jul 22, 2011 at 9:56
  • There is a JavaScript parser written in Common Lisp at marijnhaverbeke.nl/parse-js – Terje Norderhaug Commented Jul 22, 2011 at 15:35
  • Yes it is possible, but is it worth the effort? – Hamza Yerlikaya Commented Jul 22, 2011 at 19:02
Add a comment  | 

5 Answers 5

Reset to default 5

Yes, although it wouldn't really make sense.

Clojure -> JavaScript makes sense because:

  • JavaScript is the only suitable target language for a wide class of web applications
  • It allows effective use of the Google Closure compiler for whole program optimisation
  • Clojure is a great "source" language because of its macro features and great support for defining expressive DSLs

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

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

Yes, this is definitely possible and a very actionable idea. You could actually use the Rhino Javascript compiler to convert the Javascript to Java classes and could then rig something up to call the Java classes from Clojure. You don't get the source code, but you can leverage the libraries in Clojure code.

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

Yes, it is possible to translate JavaScript into Clojure. Like the other dialects in the Lisp family, Clojure is well suited to build parsers and compilers for other languages.

You can only do that with Chlorinejs, a subset of Clojure that share many things with javascript. https://github.com/chlorinejs/chlorine/wiki https://github.com/chlorinejs/chloride

发布评论

评论列表(0)

  1. 暂无评论