Guys, I'm just starting out with Clojure - so be gentle - but I am a seasoned Java developer with some LISP in the background...
I'm adding Clojure to a highly concurrent and metadata driven project that I am working on, to use as a DSL - specifically a query language.... I have a requirement to pull unknown Java classes out of an Object, construct instances of them and plug these back into other Objects...efficiently... this seems to be suprisingly difficult - or maybe I just misunderstand : $ java -fullversion java full version "1.6.0_11-b03" $ java -jar ~/.m2/repository/org/clojure/clojure/1.1.0/ clojure-1.1.0.jar Clojure 1.1.0 user=> ;; let's try a literal class : user=> (type java.lang.Integer) java.lang.Class user=> (new java.lang.Integer 1) 1 user=> (java.lang.Integer. 1) 1 user=> ;; ok - exactly as expected - now let's try a parameterised class : user=> (def my-class java.lang.Integer) #'user/my-class user=> (type my-class) java.lang.Class user=> (new my-class 1) java.lang.IllegalArgumentException: Unable to resolve classname: my- class (NO_SOURCE_FILE:8) user=> ;; aarrgh - 'new is a special form !!! user=> ;; I can't use the second form (my-class.) for obvious reasons user=> ;; so what do I do ? I came up with : user=> (defn make-instance [class & args] (eval (list* 'new class args))) #'user/make-instance user=> (make-instance my-class 1) 1 user=> ;; but this looks really slow :-( user=> $ My queries need to create a transforming function that takes a class and its ctor args and returns an immutable instance at as-close-to- java-speed-as-is-possible, as it is a potential bottleneck. It strikes me that this is a very bad place to have an eval. Can anyone help me in filling in the dots below with the least overhead possible ? (defn make-instance [class args] ...) I have all the ctor arg types in my hand as well and went on to think that I could actually write a (defn make-ctor [class types] ...) which would return me : (fn [#^type1 arg1 #^type2 arg2...#^typen argn]...) then pass this off as the to-be-called-frequently fn mentioned above, but my efforts to write this still all ended up returning a fn that used eval, as above...... so for the moment, I'm stumped hence throwing myself upon the mercy of this list. thanking you in advance for all your help, Jules -- 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