Created
August 24, 2010 19:21
-
-
Save Chouser/548144 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol Pair (a [_]) (b [_])) | |
(defmethod print-method user.Pair [o w] | |
(.write w (str "#<Pair[" (.getName (class o)) "] " (a o) ", " (b o) ">"))) | |
(deftype PairType [a b] | |
Pair | |
(a [_] a) | |
(b [_] b)) | |
(PairType. 1 2) | |
;=> #<Pair[user.PairType] 1, 2> | |
(defrecord PairRec [a b] | |
Pair | |
(a [_] a) | |
(b [_] b)) | |
(remove-method print-method PairRec) | |
(prefer-method print-method user.Pair clojure.lang.IPersistentMap) | |
(PairRec. 1 2) | |
;=> #<Pair[user.PairRec] 1, 2> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment