On Aug 11, 7:03 pm, Shantanu Kumar <kumar.shant...@gmail.com> wrote: > I tried to assign a data type to a var and then instantiate it using > the var, but it doesn't seem to work: > > user=> (defrecord X []) > user.X > > user=> (X.) > #:user.X{} > > user=> X > user.X > > user=> (def hey X) > #'user/hey > > user=> (hey.) > java.lang.IllegalArgumentException: Unable to resolve classname: hey > (NO_SOURCE_FILE:59) > > user=> (new X) > #:user.X{} > > user=> (new hey) > java.lang.IllegalArgumentException: Unable to resolve classname: hey > (NO_SOURCE_FILE:61) > > user=> (apply new hey) > java.lang.Exception: Unable to resolve symbol: new in this context > (NO_SOURCE_FILE:62) > > Can anybody help me understand how to accomplish this when using the > var? This will give me a generic way to instantiate the type when I > know the parameters. > > Regards, > Shantanu
There is no way to do this without using Java reflection, see e.g. user=> (defrecord A []) user.A user=> (def x A) #'user/x user=> (.newInstance x) #:user.A{} user=> Note .newInstance is a simple example and only works for no-arg constructor. See, e.g., http://download.oracle.com/javase/tutorial/reflect/member/ctorInstance.html -- 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