Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from djtrack16/parens.clj
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/2e7af7510d563b4345bd to your computer and use it in GitHub Desktop.
Save amalloy/2e7af7510d563b4345bd to your computer and use it in GitHub Desktop.
(fn [o]
(set
((fn q [s o c]
(apply concat
(let [a (when (pos? o)
(q (concat s "(") (dec o) (inc c)))
b (when (pos? c)
(q (concat s ")") o (dec c)))]
(if (and (zero? o) (zero? c))
[[(clojure.string/join s)]]
[a b]))))
"" o 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment