Created
September 15, 2011 19:02
-
-
Save tel/1220157 to your computer and use it in GitHub Desktop.
Default protocal implementations?
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 AProtocol | |
(say-hello [this]) | |
(location [this])) | |
(defrecord Place [name]) | |
(extend-protocol AProtocol | |
Object | |
(say-hello [this] (str "Hello " (location this))) | |
Place | |
(location [this] (str (:name this)))) | |
(defrecord HappyPlace [name]) | |
(extend-protocol AProtocol | |
HappyPlace | |
(say-hello [this] (str "HELLO " (location this) "!")) | |
(location [this] (str (:name this)))) | |
(say-hello (Place. "World")) | |
;; No implementation of method: :say-hello of protocol: #'user/AProtocol found for class: user.Place | |
;; [Thrown class java.lang.IllegalArgumentException] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment