The `new` reader macro must resolve its first argument at compile time.

That's why (new (symbol s)) doesn't work.

Thanks,
Ambrose


On Wed, Aug 6, 2014 at 6:55 PM, Colin Yates <colin.ya...@gmail.com> wrote:

> Ah OK, I didn't realise I needed to get into Java interop.
>
> For education - can you (or anyone) explain me as to why what I was trying
> didn't work?
>
> Thanks Ambrose.
>
>
> On 6 August 2014 11:50, Ambrose Bonnaire-Sergeant <
> abonnaireserge...@gmail.com> wrote:
>
>> Hi Colin,
>>
>> If you must call the Java constructor, you need reflection.
>>
>> user=> (defrecord B [c])
>> user.B
>> user=> (def s "user.B")
>> #'user/s
>> user=> (.newInstance (first (.getDeclaredConstructors (Class/forName s)))
>> (object-array [1]))
>> #user.B{:c 1}
>>
>> Thanks,
>> Ambrose
>>
>>
>> On Wed, Aug 6, 2014 at 6:37 PM, Colin Yates <colin.ya...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> tldr; if I have a (defrecord MyRecord) in ns a.b.c and I have a string
>>> "a.b.c.MyRecord" how I can invoke (a.b.c.MyRecord.) (or (new
>>> a.b.c.MyRecord)?
>>>
>>> I thought this was going to be as simple as (defn cfn "a.b.c.MyRecord")
>>> ((symbol cfn).) but that throws an ArityException: wrong number of args (0)
>>> passed to Symbol.  I
>>>
>>>  I have a protocol with a number of implementations.  Each installation
>>> will have a single implementation and will chose one based on an
>>> environment variable.  At runtime I need to look at that environment
>>> variable which defines the fully qualified implementation of a protocol.  I
>>> then need to instantiate that record.
>>>
>>> Architecturally equivalent to a simple plugin system.  I could alias
>>> them all but that requires knowing about all the implementations which is a
>>> no-go.
>>>
>>> This is where I feel the pain of not having OSGi :).
>>>
>>> Thanks all!
>>>
>>> --
>>> 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
>>> ---
>>> 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 clojure+unsubscr...@googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> 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
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Clojure" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/clojure/fp7I-zAuu2c/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> clojure+unsubscr...@googlegroups.com.
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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
> ---
> 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 clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to