Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defprotocol PStack
- "A stack protocol"
- (push [this val] "Push an element onto the stack")
- (mypop [this] "Pop an element from the top of the stack")
- (top [this] "Return the element from the top of the stack"))
- (deftype Stack [t h]
- PStack
- (push [this val]
- (Stack. this val))
- (mypop [_] t)
- (top [_] h))
- (deftype EmptyStack []
- PStack
- (push [this val]
- (Stack. this val))
- (mypop [_] (throw (IllegalStateException. "Can't pop an empty stack")))
- (top [_] nil))
Add Comment
Please, Sign In to add comment