Created
August 12, 2014 17:31
-
-
Save pyrtsa/40ed7910e6f8ffd19d05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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