Skip to content

Instantly share code, notes, and snippets.

@dabd
Created August 13, 2015 00:05
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 dabd/0d664d953d633eff8705 to your computer and use it in GitHub Desktop.
Save dabd/0d664d953d633eff8705 to your computer and use it in GitHub Desktop.
(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]
PStack
(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