lucywang000 / clj-statecharts

State Machine and StateCharts for Clojure(Script)
https://lucywang000.github.io/clj-statecharts/
Eclipse Public License 1.0
229 stars 15 forks source link

Clarify EventLess Transitions documentation #16

Open devurandom opened 1 year ago

devurandom commented 1 year ago

The documentation on EventLess Transitions describes very well what happens when in state :s1, event :e12 happens and either guard23 or guard24 return true. If they are not true, it just says "Otherwise it would stay in :s2."

What exactly happens in this case? Will :always be evaluated again when the next event arrives while the machine is still in :s2? Specifically:

lucywang000 commented 1 year ago

Right now the :always part is only evaluated when entering the state it's defined in. i.e. :s2 in the example used in the documentation.

lucywang000 commented 1 year ago

Looks like in the statecharts specification, the :always part shall be evaluated for any event, as long as the machine is in that state.

https://statecharts.dev/glossary/automatic-transition.html

Automatic transitions are usually guarded. Such a guarded automatic transition is checked immediately after the state is entered. If the condition doesn’t hold then the machine remains in the state, with this automatic transition in play for as long as the state is active. Every time the statechart handles an event, the guard condition for these automatic transitions are checked. If the guard condition ever succeeds, then the transition happens.

I'll fix this part to comply with the standard.