Skip to content

Instantly share code, notes, and snippets.

@polgfred
Created April 27, 2010 15:10
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 polgfred/380847 to your computer and use it in GitHub Desktop.
Save polgfred/380847 to your computer and use it in GitHub Desktop.
;; return one sequence from s along with the unread input
(defn read-seq [s]
(loop [input (rest s) acc ()]
(let [[c & more] input]
(cond (= \) c) [(reverse acc) more]
(= \( c) (let [[term input] (read-seq input)]
(recur input (cons term acc)))
:else (recur more (cons c acc))))))
(println (first (read-seq (vec "(ABC(DE(FGH)I)J)"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment