Created
January 20, 2012 21:36
-
-
Save brodyberg/1649734 to your computer and use it in GitHub Desktop.
Protocol invocation
This file contains 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 FIXO | |
(fixo-push [fixo value]) | |
(fixo-pop [fixo]) | |
(fixo-peek [fixo]) | |
(fixo-limit [fixo])) | |
(extend-type clojure.lang.IPersistentVector | |
FIXO | |
(fixo-push [vector value] (conj vector 4)) | |
(fixo-peek [vector] (peek vector)) | |
(fixo-pop [vector] (pop vector)) | |
(fixo-limit [vector limit] limit)) | |
(defn fixed-fixo | |
([limit] fixed-fixo limit []) | |
([limit vector] | |
(reify FIXO | |
(fixo-push [this value] | |
(if (< (count vector) limit) | |
(fixed-fixo limit (conj vector 5)) | |
this)) | |
(fixo-peek [_] (peek vector)) | |
(fixo-pop [_] (pop vector)) | |
(fixo-limit [_] limit)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment