Wow, that was fast. Thanks.

This could work but only partially.

(let [stuff car]
  (new stuff 1982 "Mercedes")
  (new stuff 2001 "Seat")
  ...)

I could take advantage of the fact that records are maps:
(let [stuff (car. 1982 "Mercedes")]
   ... use Mercedes...
   (assoc stuff :year 2001 :manufacturer "Seat"))

But this will work only if all my types have the same parameters. If
bike would be:

(defrecord bike [manufacturer year type])

then i'm stuck again.

Razvan

On Oct 6, 8:32 pm, Aaron Bedra <aaron.be...@gmail.com> wrote:
> Assuming you want to do things with the record later, why not just
> create it in the let binding
>
> (let [foo (->car 1982 "Mercedes")]
>   ...)
>
> or
>
> (let [foo (car. 1982 "Mercedes")]
>   ...)
>
> or even
>
> (let [foo (map->car {:year 1982 :manufacturer "Mercedes"})]
>   ...)
>
> or if you must
>
> (let [foo #user.car{:year 1982 :manufacturer "Mercedes"}]
>   ...)
>
> Cheers,
>
> Aaron Bedra
> --
> Clojure/corehttp://clojure.com
>
> On 10/06/2011 01:27 PM, Razvan Rotaru wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I want to instantiate a record, but having the record type as value at
> > runtime.
>
> > Example:
> > (defrecord car [year manufacturere])
> > (defrecord bike [year manufacturere])
> > (defrecord boat [year manufacturer])
>
> > I want to do (new stuff 1982 "Mercedes"), but having the record type
> > kept in the variable "stuff". Something like:
>
> > (let [stuff car]
> >   (new stuff 1982 "Mercedes"))
>
> > (let [stuff bike]
> >   (new stuff 1990 "Harley Davidson"))
>
> > Obviously new does not work. I'm gratefull for suggestions of how to
> > do it best.
>
> > Thanks,
> > Razvan

-- 
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

Reply via email to