[erlang-questions] Proposal for new state machine engine: gen_statem

Raimo Niskanen <>
Fri Feb 19 16:43:55 CET 2016


On Wed, Feb 10, 2016 at 01:56:48PM +0100, Raimo Niskanen wrote:
> Hi all!
> 
> I have created a pull request for a new state machine engine in the gen_*
> framework.  There is a heated discussion right now on GitHUB:
> 
>     https://github.com/erlang/otp/pull/960
> 
> Please contribute with an opinion.


I pushed some updates to the branch. Major changes:

* New return values from the state functions: {stop,Reason} |
  {keep_state,...} | {keep_state_and_data,...}. It turned out that the old
  [Op] was essential to an internal use case of ours and that can now be done
  with {keep_state_and_data,[Op]}.
* Change initial PrevState to undefined.
* Rewrite of terminology and types: state_data() -> data(), StateOp ::
  state_operation() -> Op :: transition_action() and more.
* Some more documentation cleanup


Two questions still remain:

* Should we change the return format from init/1 from
  {'ok',state(),data()} to {callback_mode(),state(),data()} and remove the
  init/enter_loop option {'callback_mode',callback_mode()}? I think I am for
  making the option mandatory this way or some similar.

* If there are multiple transaction_option() in a state function return
  Ops, which one shall win, the first or the last? Currently the last wins to
  harmonize with that all Ops are executed in list order so the last one
  overrides the previous. This way you can not override a value by consing it
  to the head of Ops - you will have to append it instead, which is a bit
  uncommon.


The documentation still lack early examples, but hopefully the Description
is easier to understand now... Opinions on the current version, please?!


Updated documentation at:
  http://erlang.org/~raimo/doc-7.2/lib/stdlib-2.7/doc/html/gen_statem.html

Updated OTP 18.2 .beam files at:
  https://github.com/erlang/otp/pull/erlang.org/%7Eraimo/OTP-18.2-stdlib-ebin-gen_statem.tgz
  keep the original around.

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list