Skip to content

Instantly share code, notes, and snippets.

@jakub-stastny
Last active February 13, 2023 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakub-stastny/ed50811d1459f4376929c248137a00e3 to your computer and use it in GitHub Desktop.
Save jakub-stastny/ed50811d1459f4376929c248137a00e3 to your computer and use it in GitHub Desktop.
(defprotocol Version
"Version numbers of various levels connected by a dot: X.Y.Z"
(stringify [this] "Get string representation"))
(deftype QID
[a b c d] Version
(stringify [this]
(str (.a this) "." (.b this) "." (.c this) "." (.d this))))
(defmethod print-method QID [object out]
(.write out (str (stringify object))))
(println (stringify (QID. 4 0 0 1))) ; 4.0.0.1 calling explicitly
(println (str (QID. 4 0 0 1))) ; user.QID@5f38e560 <===== ?
(println (QID. 4 0 0 1)) ; 4.0.0.1 print-method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment