Created
March 26, 2014 21:30
-
-
Save leikind/9794053 to your computer and use it in GitHub Desktop.
defprotocol/defrecord example
This file contains 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 Inspect (inspect [c])) | |
(defprotocol Maths | |
(plus [this another]) | |
(multiply [this another])) | |
(defrecord Rational [nom den] | |
Inspect | |
(inspect [this] (str (:nom this) "/" (:den this) )) | |
Maths | |
(plus [this another] | |
(Rational. | |
(+ | |
(* | |
(:nom this) | |
(:den another)) | |
(* | |
(:nom another) | |
(:den this))) | |
(* | |
(:den this) | |
(:den another )))) | |
(multiply [this another] | |
(Rational. | |
(* | |
(:nom this) | |
(:nom another)) | |
(* | |
(:den this) | |
(:den another))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment