Skip to content

Instantly share code, notes, and snippets.

@polgfred
Created April 28, 2010 03:00
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/381666 to your computer and use it in GitHub Desktop.
Save polgfred/381666 to your computer and use it in GitHub Desktop.
(declare read-term)
;; accumulate terms from an input sequence until \)
(defn read-terms [[c & more :as input] acc]
(if (= c \)) [(reverse acc) more]
(let [[term input] (read-term input)]
(recur input (cons term acc)))))
;; read one term from an input param
(defn read-term [[c & more]]
(if (not= c \() [c more]
(read-terms more ())))
(println (first (read-term (vec "(ABC(DE(FGH)I)J)"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment