JoeCamel
JoeCamel

Reputation: 722

How to compile ClojureScript inside Clojure

I want to compile ClojureScript inside Clojure and am having some problems. I would like to do something like this:

(def x '(map (fn [n] (* n n n)) [1 2 3 4]))
(cljs->js x)

where cljs->js returns JavaScript code. I guess Himera does something similar (first reading ClojureScript from a string), but I don't know enough about ClojureScript to figure it out.

Is there are simple solution to this?

Upvotes: 4

Views: 478

Answers (2)

Arthur Ulfeldt
Arthur Ulfeldt

Reputation: 91534

once you have the clojurescript dependencies sorted out (which is it's own question) then you can just call the clojurescript emit function. this is used in the Clutch project (couchdb for clojure+clojurescript). it basically looks like this:

(js/emit (aget doc "_id") nil)

Upvotes: 0

DanLebrero
DanLebrero

Reputation: 8593

Have you look at the Himera code? Here is where the code sent by the UI is compiled, which basically calls the cljs.compiler from the clojurescript project. Note that Himera is probably a lot more complex than what you are asking for, probably you just need to get the "compilation" function working

Upvotes: 1

Related Questions