On Sun, Sep 18, 2011 at 3:40 AM, Meikel Brandmeyer <m...@kotka.de> wrote: >> Var keyword = RT.var("clojure.core", "keyword"); >> Var hashMap = RT.var("clojure.core", "hash-map"); >> hashMap.invoke(keyword.invoke("foo"), 1, keyword.invoke("bar"), x); > > This one is more simple. This is clojure code.
Since I've ended up discussing it with a few people here at The Strange Loop, I thought it opportune to provide an example of interop into CFML (another dynamic scripting language on the JVM), using a little bridge library I created: // assumes x is declared with some value... // variables.clj contains the root Clojure "binding": var core = variables.clj.clojure.core; var result = variables.clj.myns.foo( core.hash_map( core.keyword( "a" ), 1, core.keyword( "bar" ), x ) ); The bridge injects a specified set of namespaces into the root binding so they can be accessed as a nested structure with a "method missing" style mechanism used to sugar-coat the calls to invoke(). _ is automatically translated to - in symbols. We use a convention that namespace._sym() returns a reference to namespace/sym whereas namespace.sym() calls (namespace/sym) - with namespace._("sym") for symbols that aren't valid CFML identifiers. That allows us to do stuff like: var data = [ 1, 2, 3, 4, 5 ]; // native CFML array var result = core.map( core.partial( core._("*"), 3 ), data ); for (var elem in result) { // realizes result of map as each elem value is obtained writeOutput( elem & "<br />" ); } Whilst not as clean as pure Clojure, it allows for great interop as well as exposing a lot of the power of Clojure directly into our CFML code (and, yes, for anyone who thought CFML was all <tags> there is a full "JavaScript-like" scripting language in there too!). We run all our CFML code on the JBoss community project, Railo. Behind the scenes it uses clojure.lang.RT and RT.var() and .invoke() / .deref() for everything. -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Railo Technologies, Inc. -- http://www.getrailo.com/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en