Skip to content

Instantly share code, notes, and snippets.

@tel
Created September 15, 2011 19:02
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 tel/1220157 to your computer and use it in GitHub Desktop.
Save tel/1220157 to your computer and use it in GitHub Desktop.
Default protocal implementations?
(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