Paste number 82940: challenge in clojure

Paste number 82940: challenge in clojure
Pasted by: Laurent Petit
When:2 years, 7 months ago
Share:Tweet this! | http://paste.lisp.org/+1RZW
Channel:None
Paste contents:
Raw Source | XML | Display As
;; file: challenge.clj
;; file: challenge.clj
;; invoke from command line:
;; java -cp clojure.jar /path/to/challenge.clj “()” “((([[]])))” … …

(ns challenge)

(def push conj)
(def closing-counterpart { \( \), \[ \] })
(defn matching-pair? [left right] 
  (= right (closing-counterpart left)))

(defn consume-one [stack c]
  (if (matching-pair? (peek stack) c)
    (pop stack)
    (push stack c)))

(defn balanced? [s] 
  (empty? (reduce consume-one [] s)))

(defn main [] 
  (apply print (map balanced? *command-line-args*)))

(when *command-line-args* 
  (main))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.