Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: DSL for final states; enhance to_dot also #6

Open
chuckremes opened this issue Jul 7, 2011 · 2 comments
Open

enhancement: DSL for final states; enhance to_dot also #6

chuckremes opened this issue Jul 7, 2011 · 2 comments

Comments

@chuckremes
Copy link

When building state machines, I often have final/terminal states where any new event cannot cause a transition out of that state. I usually define it like so:

state :a_final_state do
default :a_final_state, :log_event # transitions to self and logs the wayward event
end

I'm "abusing" the #default event handler here a bit. It would be nice if this could be encapsulated as part of the DSL.

e.g.

final_state :a_state do
event :any, :log_event # :any would be a magic symbol
end

ALTERNATELY

trans :a_state, :any, :a_state, :log_event # again, :any is magic

Additionally, I would like to request that the #to_dot functionality be enhanced so that final states were indicated as such in the dot graphic. If I am remembering my DFA notation correctly, the final state(s) would have a double-circle around them.

@slagyr
Copy link
Owner

slagyr commented Jul 8, 2011

Why do you feel that using the #default handler is abusive?

Micah

On Jul 7, 2011, at 1:59 PM, chuckremes wrote:

When building state machines, I often have final/terminal states where any new event cannot cause a transition out of that state. I usually define it like so:

state :a_final_state do
default :a_final_state, :log_event # transitions to self and logs the wayward event
end

I'm "abusing" the #default event handler here a bit. It would be nice if this could be encapsulated as part of the DSL.

e.g.

final_state :a_state do
event :any, :log_event # :any would be a magic symbol
end

ALTERNATELY

trans :a_state, :any, :a_state, :log_event # again, :any is magic

Additionally, I would like to request that the #to_dot functionality be enhanced so that final states were indicated as such in the dot graphic. If I am remembering my DFA notation correctly, the final state(s) would have a double-circle around them.

Reply to this email directly or view it on GitHub:
#6

@chuckremes
Copy link
Author

I feel it's abusive because the intent in this situation isn't absolutely clear. Using new syntax (like #final_state) would make the intent very clear IMO.

Also, using the #default handler trick doesn't forbid adding more events to that state in the future. So, a state that was considered to be final could become non-final just by adding one more event.

e.g.

this one is final

state :foo do
default :log_event
end

this one is not final

state :bar do
default :log_event
event :oops, :error
end

If we had syntax to enforce the finality of the state, the second situation would not be allowed.

e.g.
final_state :baz do
event :any, :log_event
event :oops, :error # a second event definition is not allowed!
end

Anyway, just a thought. I can clearly get what I need from existing syntax. My enhancement suggestion was merely to make the intent clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants