On Mon, May 9, 2011 at 17:50, Chris Perkins <chrisperkin...@gmail.com>wrote:
> On May 9, 8:00 am, Simon Katz <nomisk...@gmail.com> wrote: > > I'm trying to implement a function similar to new, but where > > the type is not known at compile time -- so I want to evaluate > > the first argument. > > > > With the help of Google, I found the approach used in new* > > below: > > > > (ns dynamic-new) > > > > (defn new* [type-name-as-symbol & args] > > (clojure.lang.Reflector/invokeConstructor > > (resolve type-name-as-symbol) > > (to-array args))) > > > Now my questions: > > > > Q1. Is this basically the right approach, or is there some other > > way to implement new*? > > > > Is there a reason that you need to pass a symbol, rather than the > Class object itself? Passing the class object does exactly what I want. Thanks! Simon -- 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