defrecord constructor woes

2011-01-25 Thread Mike
Quick question...I am trying to populate a record with values provided
in a list.  I'm definitely doing it the wrong way...but maybe there's
no good way to do it.

Here's what I do (clojure 1.2.0 by the way):

(defrecord Foo [x y z])
(Foo. 1 2 3)

#:user.Foo{:x 1, :y 2, :z 3}

but then:

(apply Foo. (range 1 4))

java.lang.ClassCastException: java.lang.Class (NO_SOURCE_FILE:0)

I'm running into syntax issues here...I can't apply new:

(apply new '(Foo 1 2 3))

java.lang.Exception: Unable to resolve symbol: new in this context
(NO_SOURCE_FILE:28)

Do I need to make a macro here to expand my argument list at compile
time?  I'm thinking this is a pretty fast solution, but I'd hate to
make a macro if I'm just doing it wrong.

Thanks in advance,
Mike

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


Re: defrecord constructor woes

2011-01-25 Thread Meikel Brandmeyer
Hi,

constructors (like methods) are not first class. You have to wrap it
in a factory function.

(defn make-foo
  [a b c d]
  (Foo. a b c d))

(apply make-foo [1 2 3 4])

Sincerely
Meikel

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


Re: defrecord constructor woes

2011-01-25 Thread Mike
thanks!!!

On Jan 25, 8:55 am, Meikel Brandmeyer  wrote:
> Hi,
>
> constructors (like methods) are not first class. You have to wrap it
> in a factory function.
>
> (defn make-foo
>   [a b c d]
>   (Foo. a b c d))
>
> (apply make-foo [1 2 3 4])
>
> Sincerely
> Meikel

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