Last active
November 20, 2015 22:24
-
-
Save ztellman/865e62c3a6d13296fccb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn- queue [] | |
#+clj clojure.lang.PersistentQueue/EMPTY | |
#+cljs cljs.core/PersistentQueue.EMPTY) | |
(defn matching-inputs | |
"Returns a lazy sequence of input sequences which the automaton will match." | |
[fsm] | |
(let [fsm (-> fsm ->dfa final-minimize) | |
accept? (set (accept fsm)) | |
q (atom (conj (queue) [(start fsm) []]))] | |
(take-while | |
#(not (identical? ::none %)) | |
(repeatedly | |
(fn [] | |
(loop [] | |
(if-let [[state path] (peek @q)] | |
(do | |
(swap! q pop) | |
(doseq [[i s] (input->state fsm state)] | |
(swap! q conj [s (conj path i)])) | |
(if (accept? state) | |
path | |
(recur))) | |
::none))))))) |
domkm
commented
Nov 20, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment