Archive

Posts Tagged ‘clojurescript’

ClojureScript One Execution Flow

January 28th, 2012 No comments

Last night I puzzled through the execution flow of the ClojureScript One sample app. I even took notes while I was doing it.

The results are here.

I have to say ClojureScript One is an impressive achievement. Someone should build “Clojure One” now :)

Categories: clojure Tags: ,

I did a bad thing with ClojureScript

July 20th, 2011 2 comments

UPDATE: Don’t do this. It’s a joke and (js*) is an internal detail of ClojureScript. If you need to access native code, access it through the js namespace.


Tonight ClojureScript was announced and made available. I’m interested in how JavaScript interop works for environments like node.js, CouchDB, etc. So far, it seems like (js*) is the main entry point to JavaScript land and functions like (aset) can also be used:

$ script/repljs 
#'user/jse
"Type: " :cljs/quit " to quit"
ClojureScript:cljs.user> (def something (js* "{x: 100}"))
#<[object Object]>
ClojureScript:cljs.user> (.x something)
100
ClojureScript:cljs.user> (aget something "x")
100
ClojureScript:cljs.user> (aset something "y" 99)
99
ClojureScript:cljs.user> (.y something)
99

It happens that repljs (the ClojureScript repl) runs in Rhino which is ripe for abuse:

$ script/repljs 
#'user/jse
"Type: " :cljs/quit " to quit"
ClojureScript:cljs.user> (def f 
  (js* "new Packages.javax.swing.JFrame(\"ClojureScript!!\")"))
#<javax.swing.JFrame ... >
ClojureScript:cljs.user> (js* "~{f}.setVisible(true)")
#<undefined>

Yes. I am a bad person. I will try to do something useful with ClojureScript shortly.

Also note the interpolation syntax, ~{f}, for referring to Clojure bindings in JavaScript.

Categories: clojure Tags: ,