Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
Created August 12, 2014 17:31
Show Gist options
  • Save pyrtsa/40ed7910e6f8ffd19d05 to your computer and use it in GitHub Desktop.
Save pyrtsa/40ed7910e6f8ffd19d05 to your computer and use it in GitHub Desktop.
(fn [{:keys [states start accepts transitions]}]
(->> (conj clojure.lang.PersistentQueue/EMPTY {:prefix [], :pos start})
(iterate (fn [q]
(let [[{:keys [prefix pos]} tail] ((juxt peek pop) q)]
(into tail (for [[alpha pos'] (transitions pos)]
{:prefix (conj prefix alpha), :pos pos'})))))
(take-while peek)
(map peek)
(filter (comp accepts :pos))
(map (comp (partial apply str) :prefix))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment