Closed MartinBroers closed 5 months ago
In the past I have used SMs with on_entry
and on_exit
so this is definitely something that I miss here.
I have a working branch in https://github.com/MartinBroers/smlang-rs/tree/add-on-entry-on-exit, so if anyone wants to have a look at it already and have some early feedback, be most welcome :-)
@MartinBroers, what is the state of this? I may take a crack at it.
I haven't worked on it since I published my own branch, which is working for me, but I think there's a few things to improve. I'll open an MR here so you have a base to start from and I do accept comments, remarks, improvement points and patches to get this in.
Implemented in https://github.com/korken89/smlang-rs/pull/66
When I am implementing a state machine which represents a traffic light, I want to have repetitive actions when I enter, for example, state Green. I could solve that by using an action, but that action could be the same for multiple transitions. Let's say I have the following definition:
So, this works. Every transition allows me to have the correct lights on- and off. However, this results in code repetition I don't want. So, when I am entering the
Green
state, I want to enable the Green light. When I am exiting the Orange state, I want to disable the orange light.So, if we could define something like
And then
Although I am really unsure about the notation. Now that I read boost-sml: https://boost-ext.github.io/sml/examples.html#states, this is what they do:
Then you'd get something like
Let me know your thoughts. Very curious about the notation how you guys think about it. I also want to help to implement it.