Re:ClojureScript Compiler Compiled with ClojureScript
by S4M on Thursday December 20, 2012 @10:03AM
(#4948024)
I never ran ClojureScript, but I am curious about the procedure to call functions from other java script libraries. Is it as seamless as the call of a java function from the JVM Clojure?
[ Parent
| on HN ]
Re:ClojureScript Compiler Compiled with ClojureScript
by piranha on Thursday December 20, 2012 @10:15AM
(#4948085)
Yes, it is. You can just do (js/$ ".something") and you'll get jQuery object back.
Re:ClojureScript Compiler Compiled with ClojureScript
by dribnet on Thursday December 20, 2012 @12:12PM
(#4948716)
And if you are lucky enough to be dealing with a functional javascript library like d3, you can even use cljs functions as arguments to your js library. This leads to very succinct and powerful interop.
For example:
(.timer js/d3 (fn []
(-> root (.selectAll "g") (.data curClockData)
(.select "path")
(.attr "class" #(str (:key %) (:which %))))
; return false to keep running
false))))
This snippet does this twice to provide a longish function to the d3.timer call and a small inline one to attr to set a class based on the data in the selection. More context available: http://bl.ocks.org/4326896ObTopic: cljs in cljs does sound dreamy. Would this also enable <script type="text/clojurescript">?
Re:ClojureScript Compiler Compiled with ClojureScript
by swannodette on Thursday December 20, 2012 @12:47PM
(#4948911)
Nice D3 example!
I predict we will see an "official" CLJS-in-CLJS around the time of the next Clojure/conj ;)
Re:ClojureScript Compiler Compiled with ClojureScript
by kanaka on Monday December 24, 2012 @04:13PM
(#4964110)
And hopefully "unofficial" CLJS-in-CLJS by Clojure West. :-)
I just pushed type/record/protocol/reify support. Next big thing is to fix runtime namespace creation. Then file I/O. Then all the bugs discovered while try to compile the compiler using the compiled compiler (i.e. self-hosting).
Re:ClojureScript Compiler Compiled with ClojureScript
by pepijndevos on Thursday December 20, 2012 @11:39AM
(#4948545)
I think he meant the reverse. I know it is fairly doable in Clojure on the JVM, I assume ClojureScript is fairly similar. You have to use Var objects iirc.
Re:ClojureScript Compiler Compiled with ClojureScript
by dustingetz on Thursday December 20, 2012 @12:38PM
(#4948862)
when calling JS code from CLJS, you have to translate arguments that aren't primitives from CLJS datastructures to JS datastructures. (Functional languages implement their datastructures differently than imperative languages.)
here's an example: https://github.com/dustingetz/getz-bootstrap/blob/datomic/sr...
Re:ClojureScript Compiler Compiled with ClojureScript
by eggsby on Thursday December 20, 2012 @02:49PM
(#4949552)
While it's true that you need to turn things like a NodeList from js into a clj seq you don't need to write these utilities yourself; clj->js and js->clj can both be found in cljs core:
https://github.com/clojure/clojurescript/blob/master/src/clj...