Re: Creating instances of types not known at compile time

2011-05-10 Thread Simon Katz
On May 10, 8:27 am, Meikel Brandmeyer wrote: > Hi, > > Am 10.05.2011 um 01:49 schrieb Simon Katz: > > > Passing the class object does exactly what I want. > > Then passing a factory function will work, too—without reflection. Much more > performance impact then checking a short string for a dot.

Re: Creating instances of types not known at compile time

2011-05-10 Thread Meikel Brandmeyer
Hi, Am 10.05.2011 um 01:49 schrieb Simon Katz: > Passing the class object does exactly what I want. Then passing a factory function will work, too—without reflection. Much more performance impact then checking a short string for a dot. Sincerely Meikel -- You received this message because yo

Re: Creating instances of types not known at compile time

2011-05-09 Thread Simon Katz
On Mon, May 9, 2011 at 17:50, Chris Perkins wrote: > On May 9, 8:00 am, Simon Katz 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 approa

Re: Creating instances of types not known at compile time

2011-05-09 Thread Chris Perkins
On May 9, 1:49 pm, Alan wrote: > On May 9, 9:50 am, Chris Perkins wrote: > > A mild gripe: we're in a language that doesn't make us use ugly names > like klass and clazz. Some will disagree with me for sure, but I think > it's more readable to simply use the symbol "class" when you're > talking a

Re: Creating instances of types not known at compile time

2011-05-09 Thread Alan
On May 9, 9:50 am, Chris Perkins wrote: > On May 9, 8:00 am, Simon Katz 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 ne

Re: Creating instances of types not known at compile time

2011-05-09 Thread Chris Perkins
On May 9, 8:00 am, Simon Katz 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

Re: Creating instances of types not known at compile time

2011-05-09 Thread Jonathan Fischer Friberg
Well, that's sort of wanting to eat the cake and have it. It's impossible to resolve a symbol where it isn't known where it came from, if any resolving is to take place, it must assume to be in the current namespace. So yes, you're right; syntax-quote would work best here. Jonathan On Mon, May

Re: Creating instances of types not known at compile time

2011-05-09 Thread Shantanu Kumar
Have you considered factory functions and macros? Macros might suit better if you are dealing with various records. (defmacro instance ([^Class c] `(new ~c)) ([^Class c & more] `(new ~c ~@more))) Since macros are expanded, qualified vs unqualified issue will be taken care of automatic

Re: Creating instances of types not known at compile time

2011-05-09 Thread Simon Katz
On Mon, May 9, 2011 at 16:21, Jonathan Fischer Friberg wrote: > Q1 This macro captures the correct namespace: > > (defmacro new* [type-name-as-symbol & args] > `(clojure.lang.Reflector/invokeConstructor > (ns-resolve ~*ns* ~type-name-as-symbol) > (to-array '~args))) > Unfortunately th

Re: Creating instances of types not known at compile time

2011-05-09 Thread Jonathan Fischer Friberg
Never mind Q2, I didn't understand the question correctly. Jonathan On Mon, May 9, 2011 at 5:21 PM, Jonathan Fischer Friberg < odysso...@gmail.com> wrote: > Q1 This macro captures the correct namespace: > > (defmacro new* [type-name-as-symbol & args] > `(clojure.lang.Reflector/invokeConstructo

Re: Creating instances of types not known at compile time

2011-05-09 Thread Jonathan Fischer Friberg
Q1 This macro captures the correct namespace: (defmacro new* [type-name-as-symbol & args] `(clojure.lang.Reflector/invokeConstructor (ns-resolve ~*ns* ~type-name-as-symbol) (to-array '~args))) Q2 Backquote ` is unnecessary for symbols, use standard quote ' Q3 Answer to 1 fixes this

Creating instances of types not known at compile time

2011-05-09 Thread Simon Katz
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.R