I figured it out. I assumed it was some quirk with defrecord, but it was
an arity exception. Didn't pass 2 params to the ctor.
DERP!
;; This is the right way:
(Vec2. (+ (:x this) (:x other))
(+ (:y this) (:y other)))
On Wednesday, 31 July 2013 17:51:36 UTC-7, JvJ wrote:
>
> I tried to define this record, but the Vec2. constructor doesn't exist yet.
> How can I use the constructor inside the record's method?
>
> (defrecord Vec2 [x y]
>
> Vector
> (mag [this]
> (Math/sqrt
> (+ (* x x) (* y y))))
>
> (v+ [this] this)
> (v+ [this other]
> (Vec2. (+ (:x this) (:x other)
> (:y this) (:y other))))
> (v+ [this a b & c]
> (reduce v+
> this
> (conj c b a))))
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.