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 replace that ugly bit in
the middle.

One more thing to know about print-method for deftype: The deftype macro generates a default implementation for deftype. Defining your own replaces the default version, which in most situations is just fine.

However, there is a situation that requires more effort. Suppose you have a family of types for which you want to implement a common print- method. The obvious approach for any multimethod would be to declare all those types as derived from some parent (a namespace-qualified keyword will do, there is no need to have any implementation for a parent type) and have a print-method implementation for the parent. The problem is just that the type's default implementation will be used in preference to the shared one. The solution is to remove the default method using remove-method.

Konrad.

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

To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or 
reply to this email with the words "REMOVE ME" as the subject.

Reply via email to