Skip to content

Instantly share code, notes, and snippets.

@PlugIN73
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save PlugIN73/31dcd82459d3e0c6669e to your computer and use it in GitHub Desktop.

Select an option

Save PlugIN73/31dcd82459d3e0c6669e to your computer and use it in GitHub Desktop.
Clojure Stack implementation
(defprotocol IStack
(printStack [this])
(push [this value])
(pop [this]))
(defrecord Stack [storage] IStack
(printStack [this]
(println storage))
(push [this value]
(swap! storage conj value))
(pop [this]
(swap! storage clojure.core/pop)))
(def stack (Stack. (atom '())))
(.printStack stack)
(.push stack 1)
(.push stack 2)
(.push stack 3)
(.printStack stack)
(.pop stack)
(.printStack stack)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment