Guest User

Untitled

a guest
Jan 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. (defprotocol AProtocol
  2. (say-hello [this])
  3. (location [this]))
  4.  
  5. (defrecord Place [name])
  6.  
  7. (extend-protocol AProtocol
  8. Object
  9. (say-hello [this] (str "Hello " (location this)))
  10. Place
  11. (location [this] (str (:name this))))
  12.  
  13. (defrecord HappyPlace [name])
  14.  
  15. (extend-protocol AProtocol
  16. HappyPlace
  17. (say-hello [this] (str "HELLO " (location this) "!"))
  18. (location [this] (str (:name this))))
  19.  
  20. (say-hello (Place. "World"))
  21.  
  22. ;; No implementation of method: :say-hello of protocol: #'user/AProtocol found for class: user.Place
  23. ;; [Thrown class java.lang.IllegalArgumentException]
Add Comment
Please, Sign In to add comment