Skip to content

Instantly share code, notes, and snippets.

@gnuvince gnuvince/gist:58942
Created Feb 5, 2009

Embed
What would you like to do?
(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
You can’t perform that action at this time.