Skip to content

Instantly share code, notes, and snippets.

@Chouser
Created August 24, 2010 19:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chouser/548144 to your computer and use it in GitHub Desktop.
Save Chouser/548144 to your computer and use it in GitHub Desktop.
(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