On 21 Mar 2010, at 20:34, Fogus wrote:
(defmethod clojure.core/print-method ::Piece [piece writer] ???what
goes
here???)
(defmethod clojure.core/print-method ::Piece
[piece writer]
(.write writer (str (:number piece) (:letter piece)) 0 2))
Extending Piece to provide a str method can repla
On 21 March 2010 23:19, Meikel Brandmeyer wrote:
> The docstring of deftype says protocol, interface or Object.
So it does. (My, do I feel silly now.) Thanks!
Sincerely,
Michał
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group,
Hi,
On Sun, Mar 21, 2010 at 08:43:10PM +0100, Michał Marczyk wrote:
> But how would one go about that? str calls .toString on its arguments,
> which is in turn a method of Object, thus not present in any
> interface, whereas deftype / extend only allow one to implement
> interface or protocol met
On 21 March 2010 21:02, Mark Engelberg wrote:
> I'm kind of surprised that *print-dup* behavior isn't automatically enabled
> for deftypes. Is there a standard way to add this in for a specific
> deftype?
print-dup is just another multimethod, so an implementation of that
can be defined. Obvious
I'm kind of surprised that *print-dup* behavior isn't automatically enabled
for deftypes. Is there a standard way to add this in for a specific
deftype?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@goog
On 21 March 2010 20:40, Mark Engelberg 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)) c
On 21 March 2010 20:34, Fogus wrote:
> Extending Piece to provide a str method can replace that ugly bit in
> the middle.
But how would one go about that? str calls .toString on its arguments,
which is in turn a method of Object, thus not present in any
interface, whereas deftype / extend only al
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
What other interesting things can be overridden for
> (defmethod clojure.core/print-method ::Piece [piece writer] ???what goes
> here???)
(defmethod clojure.core/print-method ::Piece
[piece writer]
(.write writer (str (:number piece) (:letter piece)) 0 2))
Extending Piece to provide a str method can replace that ugly bit in
the middle.
-m
--
On 21 March 2010 20:10, Mark Engelberg wrote:
> I have tried things like:
> (defmethod clojure.core/print-method ::Piece [piece writer] (do (pr (:number
> piece) writer) (pr (:letter piece) writer)))
> but it doesn't work.
You need to replace pr with print-method inside the do. pr doesn't
accept
10 matches
Mail list logo