Re: Java Class Factory

2009-12-03 Thread Meikel Brandmeyer
Hi, On Dec 3, 4:46 pm, lazy1 wrote: > >> What is the right way to do this? > > (defn new-container > >  [type] > > (.newInstance (*containers* type))) > > (defmacro new-container [type] > > `(new ~(*containers* type))) > > Thanks! These are both great and also very educational. > > The reason fo

Re: Java Class Factory

2009-12-03 Thread lazy1
Hello All, >> What is the right way to do this? > (defn new-container > [type] > (.newInstance (*containers* type))) > (defmacro new-container [type] > `(new ~(*containers* type))) Thanks! These are both great and also very educational. The reason for this coding style is that I'm writing a wr

Re: Java Class Factory

2009-12-03 Thread sross
On Dec 3, 4:15 am, lazy1 wrote: > Hello, > What is the right way to do this? As people have mentioned, new is a special form which evaluates it's arguments at compile time and cannot be used with a dynamic class name. Fortunately you can use the reflection API and create instance of your class

Re: Java Class Factory

2009-12-03 Thread Jarkko Oranen
On Dec 3, 6:15 am, lazy1 wrote: > Hello, > > I'm trying to create a "factory" method for Java classes, however I'm > doing something wrong. > > (import '(java.util Dictionary HashMap)) > > (def *containers* { :dict Dictionary :hash HashMap}) > (defn new-container >   [type] >   (new (*containers

Re: Java Class Factory

2009-12-02 Thread Dave M
On Dec 2, 11:15 pm, lazy1 wrote: > Hello, > > I'm trying to create a "factory" method for Java classes, however I'm > doing something wrong. > > (import '(java.util Dictionary HashMap)) > > (def *containers* { :dict Dictionary :hash HashMap}) > (defn new-container >   [type] >   (new (*container

Re: Java Class Factory

2009-12-02 Thread ataggart
On Dec 2, 8:15 pm, lazy1 wrote: > Hello, > > I'm trying to create a "factory" method for Java classes, however I'm > doing something wrong. > > (import '(java.util Dictionary HashMap)) > > (def *containers* { :dict Dictionary :hash HashMap}) > (defn new-container >   [type] >   (new (*containers

Re: Java Class Factory

2009-12-02 Thread Mike Hinchey
(new) tries to resolve the argument at compile-time, not runtime. You need to spell out each (new class) in a cond. You might write a macro to make it a little less verbose. -Mike -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this grou

Java Class Factory

2009-12-02 Thread lazy1
Hello, I'm trying to create a "factory" method for Java classes, however I'm doing something wrong. (import '(java.util Dictionary HashMap)) (def *containers* { :dict Dictionary :hash HashMap}) (defn new-container [type] (new (*containers* type))) (def d (new-container :dict)) The above gi