automat icon indicating copy to clipboard operation
automat copied to clipboard

Automaton with `a/not` triggers handlers unexpectedly

Open osfameron opened this issue 8 years ago • 0 comments

Again, apologies if I'm misunderstanding the docs - from the main docs "The not operator is equivalent to the regex ^ flag for negating character classes". Running viz/view on trivial (one-node) automata this fits my understanding, however the following example of a word-count automaton fails:

(defn word+ [v _] (inc v))

(def word [\a])

(def !word (a/not word))

(def word-count-with-not
  (a/compile 
    (a/*
      (a/or 
        [(a/+ !word)]
        [[(a/+ word) !word] (a/$ :word+)]))
    {:reducers {:word+ word+}}))

(:value (reduce #(a/advance word-count-with-not    %1 %2) 0 "aaa aa aaaaaa.")) ;=> 6?!

If I preprocess the machines with a signal instead, the logic seems to be correct:

(def word-count-with-signal
  (a/compile 
    (a/*
      (a/or 
        [(a/+ false)]
        [[(a/+ true) false] (a/$ :word+)]))
    {:signal (partial = \a)
     :reducers {:word+ word+}}))

(:value (reduce #(a/advance word-count-with-signal %1 %2) 0 "aaa aa aaaaaa.")) ;=> 3

Comparing the state machines with viz.view, it looks like the :word+ event is triggered, unexpectedly, after the 2nd (a/+ word) iteration.

osfameron avatar Jan 12 '17 19:01 osfameron