(defrecord Person [name])
(defmulti read-tag (fn [name & args] (keyword "myns" name)))
(defmethod read-tag :myns/person
[tag name]
(Person. name))
(read-tag "person" "david")
=> #:myns.Person{:name "david"}
But I agree with everyone else, there's no need to use records unless
you're addicted
On Thu, Feb 3, 2011 at 10:11 PM, Aaron Cohen wrote:
> On Thu, Feb 3, 2011 at 10:04 PM, Quzanti wrote:
>>
>>
>>> I see no reason for the ctor to be defined as a string as you've done with
>>> "Person.".
>>
>> The reason is that I am reading in XML and mapping a tag name to the
>> record class.
>
>
On Thu, Feb 3, 2011 at 10:04 PM, Quzanti wrote:
>
>
>> I see no reason for the ctor to be defined as a string as you've done with
>> "Person.".
>
> The reason is that I am reading in XML and mapping a tag name to the
> record class.
It's possible to do this using reflection, but I don't recommend
On Feb 4, 3:04 am, Kevin Downey wrote:
> then define a factory function when you define the record, and use
> that, you can easily apply a function to arbitrary arguments without
> using eval
>
Thanks. There may be something in that. Would there be an easy way of
dynamically determining which f
then define a factory function when you define the record, and use
that, you can easily apply a function to arbitrary arguments without
using eval
On Thu, Feb 3, 2011 at 7:00 PM, Quzanti wrote:
>
>
> On Feb 4, 2:55 am, Kevin Downey wrote:
>> I strongly recommend against writing or designing anyt
> I see no reason for the ctor to be defined as a string as you've done with
> "Person.".
The reason is that I am reading in XML and mapping a tag name to the
record class.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send
On Feb 4, 2:55 am, Kevin Downey wrote:
> I strongly recommend against writing or designing anything that
> requires dynamically generating defrecords. if you want to dynamically
> generate classes I suggest getting familiar with the asm library and
> reading up on classloaders.
>
Its just the i
I strongly recommend against writing or designing anything that
requires dynamically generating defrecords. if you want to dynamically
generate classes I suggest getting familiar with the asm library and
reading up on classloaders.
On Thu, Feb 3, 2011 at 6:49 PM, Quzanti wrote:
> Thanks - that mi
On Feb 4, 2:47 am, Kevin Downey wrote:
> if you really want to keep things simple you should just say
> '(Person. "..." 18)
> without all the concat noise the solution becomes obvious. you have a
> form (new Person X Y), you want to execute the code with different
> values bound to X and Y at ru
Thanks - that might well be part of the solution
Person. is dynamically determined (i.e the result of a fn too)
So I guess I am asking is there a way to dynamically resolve a
classname?
I found this
http://dev.clojure.org/jira/browse/CLJ-370?page=com.atlassian.jira.plugin.system.issuetabpanels%
if you really want to keep things simple you should just say
'(Person. "..." 18)
without all the concat noise the solution becomes obvious. you have a
form (new Person X Y), you want to execute the code with different
values bound to X and Y at runtime, sounds like a function to me.
On Thu, Feb 3,
On Feb 4, 2:23 am, Kevin Downey wrote:
> whole crazy concat thing
> which has nothing to do with anything
I probably should have clarified that the reason I need concat is that
various functions are returning subsets of the arguments as vectors,
but as stated to keep things sim
On Thu, Feb 3, 2011 at 9:36 PM, Quzanti wrote:
> I probably should have clarified that the reason I need concat is that
> various functions are returning subsets of the arguments as vectors,
> but as stated to keep things simple in the example I just used values
I still recommend using maps. Bu
On Thu, Feb 3, 2011 at 9:36 PM, Quzanti wrote:
>
>
> On Feb 4, 2:23 am, Kevin Downey wrote:
>
>> whole crazy concat thing
>> which has nothing to do with anything
>
> I probably should have clarified that the reason I need concat is that
> various functions are returning subsets o
On Thu, Feb 3, 2011 at 8:53 PM, Quzanti wrote:
> Hello. I need to dynamically define records
>
For dynamic code like this it I would recommend using plain old maps.
David
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send
18:16 hiredman
http://groups.google.com/group/clojure/browse_thread/thread/83ad2eed5a68f108?hl=en
18:17 hiredman it amazes me how convoluted people can make things
18:17 brehaut hiredman: at least he recognises it
18:17 dnolen mattmitchell: word of advice, just do the simplest
thing. OO brainwa
Hello. I need to dynamically define records
Suppose I have a record
(defrecord Person [name age])
Then to dynamically construct an instance I do a much more complex
version of
(concat [(symbol "Person.")] ["Peter"] [18])
Where things like Peter and the class of the record are actually the
resu
17 matches
Mail list logo