Skip to content

Instantly share code, notes, and snippets.

@ztellman
Last active November 20, 2015 22:24
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 ztellman/865e62c3a6d13296fccb to your computer and use it in GitHub Desktop.
Save ztellman/865e62c3a6d13296fccb to your computer and use it in GitHub Desktop.
(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
Copy link

domkm commented Nov 20, 2015

  (let [fsm (-> fsm ->dfa final-minimize)
        accept? (set (accept fsm))
        q #+clj clojure.lang.PersistentQueue/EMPTY #+cljs cljs.core/PersistentQueue.EMPTY
        q (atom (conj q [(start fsm) []]))]
...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment