Consider the following deftype:
(deftype Piece [#^int number #^char letter])
(def piece (Piece 1 \A))
Now, when I evaluate piece at the REPL, I want it to print:
1A
rather than
#:Piece{:number 1, :letter \A}
similarly, I would like (str piece) to yield "1A".
A while back, I was told on this list that the key to this was to override
print-method, but I can't quite figure out how to do it:
(defmethod clojure.core/print-method ::Piece [piece writer] ???what goes
here???)
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.
What's the trick? Thanks,
Mark
--
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.