On 21 March 2010 20:40, Mark Engelberg <[email protected]> wrote:
> Speaking of overriding methods, what am I doing wrong here:
> (deftype Piece [#^int number #^char letter]
> Comparable
> (compareTo [x y]
> (let [c1 (compare (:number x) (:number y))]
> (if (zero? c1) (compare (:letter x) (:letter y)) c1))))
deftype expects method definitions *not* to accept an explicit "self"
argument. You need to do something like this instead:
(deftype Piece [#^int number #^char letter]
Comparable
(compareTo
[x]
(let [c1 (compare number (:number x))]
(if (zero? c1) (compare letter (:letter x)) c1))))
Note that own fields can be accessed by name. If you do need a "self"
argument, you can create an implicit self available to all method
bodies by passing
:as some-symbol
to the deftype right after the fields vector.
Sincerely,
Michał
--
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
To unsubscribe from this group, send email to
clojure+unsubscribegooglegroups.com or reply to this email with the words
"REMOVE ME" as the subject.