Last active
August 29, 2015 14:04
-
-
Save PlugIN73/31dcd82459d3e0c6669e to your computer and use it in GitHub Desktop.
Clojure Stack implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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