Guest User

Untitled

a guest
May 27th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. (defprotocol PStack
  2. "A stack protocol"
  3. (push [this val] "Push an element onto the stack")
  4. (mypop [this] "Pop an element from the top of the stack")
  5. (top [this] "Return the element from the top of the stack"))
  6.  
  7. (deftype Stack [t h]
  8. PStack
  9. (push [this val]
  10. (Stack. this val))
  11. (mypop [_] t)
  12. (top [_] h))
  13.  
  14. (deftype EmptyStack []
  15. PStack
  16. (push [this val]
  17. (Stack. this val))
  18. (mypop [_] (throw (IllegalStateException. "Can't pop an empty stack")))
  19. (top [_] nil))
Add Comment
Please, Sign In to add comment