I need the ability to create one of a number of java classes which have
constructors taking a known list of parameters. There are a large enough
number of classes that having a set of conditions testing for each class
name would be unmanageable. The classes are from a third-party jar file so
I cannot modify them either.
The trouble is that new is special form and does not evaluate it's first
parameter so if I write an expression like
(new (Class/forName klassname) param1 param2) it fails
because (Class/forName klassname) is treated as the class name rather than
being evaluated first.
The closest I've got so far is to write the following macro
(defmacro make-proxy
"Build proxy class from name and map"
[klassname params] (list 'new (Class/forName klassname) '(:hostname
params) '(:port params)))
This gets me some of the way, I can now write
(make-proxy "com.example.foo" {:hostname "127.0.0.1 :port 9559})
but it only works for constant strings since the first parameter is
evaluated when the macro is expanded.
Can anyone suggest a solution?
thanks
Dave
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.