ztellman/automat

More details on $

Closed this issue · 3 comments

Could you add more details on when the reduce actions are being executed to the documentation, and show the actions in the view graph?

In the documentation it reads like the actions might be associated with the transitions, but they actually seem to be collected on each state, i.e. for :x :w input action :F is still executed because it's associated with state 1, not the transition :z.

(defn states
  [arg]
  (let [f (a/compile
            [(a/$ :A)
             (a/or
               [(a/$ :B) :x (a/$ :C)]
               [(a/$ :D) :y (a/$ :E) :z (a/$ :F)])
             (a/$ :G)
             :w
             (a/$ :H)]
            (apply merge
                   (map (fn [t] {t #(conj %1 [t %2])})
                        [:A :B :C :D :E :F :G :H])))])
  (:value (a/greedy-find f (a/start f []) arg)))

(states [:x :w])
=> [[:A :x] [:D :x] [:B :x] [:F :x] [:C :x] [:G :x] [:H :w]]
(states [:y :z :w])
=> [[:A :y] [:D :y] [:B :y] [:E :y] [:F :z] [:C :z] [:G :z] [:H :w]]

screen shot 2014-05-24 at 16 25 58

I'm actually in the process of making actions associated with inputs rather than states, this was an oversight in my original implementation. A new release with these changes (and labeling of actions in the view diagrams) will be forthcoming soon.

I've been poking at this a bit while on vacation. With the new commit, you'll get a visualization that looks like:

screen shot 2014-06-04 at 10 40 52 am

Can you confirm this is the desired behavior?

Yes, that's great!