ztellman / automat

better automata through combinators
588 stars 50 forks source link

More details on $ #2

Closed neapel closed 10 years ago

neapel commented 10 years ago

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

ztellman commented 10 years ago

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.

ztellman commented 10 years ago

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?

neapel commented 10 years ago

Yes, that's great!