Hi,
maybe you just want a factory?
(defrecord Foo [a b])
(defn make-Foo
[a b]
(Foo. a b))
(defn make
[^String class & args]
(let [last-dot (.lastIndexOf class \.)
factory (ns-resolve (symbol (subs class 0 last-dot)) (symbol (str
"make-" (subs class (inc last-dot)]
(when
test=> (def foo-class-symbol (load-string "test.Foo"))
test=> (def foo (eval (list 'new foo-class-symbol 1 2)))
test=> foo
#:test.Foo{:A 1, :B 2}
Is that what you want?
On Aug 23, 6:24 pm, Timothy Baldridge wrote:
> Given:
>
> test=>(defrecord Foo [A B])
> test=>(class (Foo. 1 2))
> test.Foo
>
>
On Aug 23, 3:39 pm, Craig Andera wrote:
> > (Class/forName "java.lang.String")
>
> Oh, does that work in 1.3? Because (new (Class/forName "user.Foo"))
> was the first thing I tried (under 1.2) and it doesn't work. Perhaps
> unsurprisingly given that new is a special form.
No. But you can use refl
> (Class/forName "java.lang.String")
Oh, does that work in 1.3? Because (new (Class/forName "user.Foo"))
was the first thing I tried (under 1.2) and it doesn't work. Perhaps
unsurprisingly given that new is a special form.
--
You received this message because you are subscribed to the Google
Gro
> Given:
>
> test=>(defrecord Foo [A B])
> test=>(class (Foo. 1 2))
> test.Foo
>
> How do I:
>
> test=>(new "test.Foo" 1 2)
> #:test.Foo{:A 1, :B 2}
>
> Currently I get " Unable to resolve classname: test/Foo".
Check out
http://stackoverflow.com/questions/3748559/clojure-creating-new-instance-fro
> Given:
>
> test=>(defrecord Foo [A B])
> test=>(class (Foo. 1 2))
> test.Foo
>
> How do I:
>
> test=>(new "test.Foo" 1 2)
> #:test.Foo{:A 1, :B 2}
>
> Currently I get " Unable to resolve classname: test/Foo".
>
> Thanks,
>
> Timothy
(Class/forName "java.lang.String")
>
Be mindful of the
Given:
test=>(defrecord Foo [A B])
test=>(class (Foo. 1 2))
test.Foo
How do I:
test=>(new "test.Foo" 1 2)
#:test.Foo{:A 1, :B 2}
Currently I get " Unable to resolve classname: test/Foo".
Thanks,
Timothy
--
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they ha