Created
February 5, 2009 19:26
-
-
Save gnuvince/58942 to your computer and use it in GitHub Desktop.
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
(def brackets (zipmap "([{<" ")]}>")) | |
(def opening-brackets (set (keys brackets))) | |
(def closing-brackets (set (vals brackets))) | |
(defn- check-aux [[x & xs] stack] | |
(if x | |
(cond (opening-brackets x) (recur xs (conj stack (brackets x))) | |
(closing-brackets x) (if (= x (peek stack)) | |
(recur xs (pop stack)) | |
false) | |
:else (recur xs stack)) | |
(empty? stack))) | |
(defn check-brackets [s] | |
(check-aux s [])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment