Skip to content

Instantly share code, notes, and snippets.

@dabd dabd/stack.clj
Created Aug 13, 2015

What would you like to do?
(defprotocol PStack
"A stack protocol"
(push [this val] "Push element in")
(pop* [this] "Pop element from stack")
(top [this] "Get top element from stack"))
(defrecord FStack [coll]
(push [_ val]
"Return the stack with the new element inserted"
(FStack. (conj coll val)))
(pop* [_]
"Return the stack without the top element"
(FStack. (rest coll)))
(top [_]
"Return the top value of the stack"
(first coll)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.