<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1476216801148_366463">Upgrade to R 19.1+. gen_statem should be marked unstable/beta in the docs. It changes too fast.</div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> On Monday, October 17, 2016 5:41 AM, Schneider <schneider@xs4all.nl> wrote:<br></font></div> <br><br> <div class="y_msg_container">Dear list,<br><br>I feel really stupid this morning, trying to get the gen_statem working. <br>Even the code_lock example given in the gen_statem behaviour <br>documentation doesn't work:<br><br>Erlang/OTP 19 [erts-8.0.5] [source] [64-bit] [smp:2:2] <br>[async-threads:10] [hipe] [kernel-poll:false]<br><br>Eshell V8.0.5 (abort with ^G)<br>1> c(code_lock).<br>{ok,code_lock}<br>2> code_lock:start_link("123").<br>Lock<br>** exception exit: {callback_mode,ok}<br><br><br>TIA,<br><br>Frans<br><br><br>-module(code_lock).<br>-behaviour(gen_statem).<br>-define(NAME, code_lock).<br><br>-export([start_link/1]).<br>-export([button/1]).<br>-export([init/1,callback_mode/0,terminate/3,code_change/4]).<br>-export([locked/3,open/3]).<br><br>start_link(Code) -><br> gen_statem:start_link({local,?NAME}, ?MODULE, Code, []).<br><br>button(Digit) -><br> gen_statem:cast(?NAME, {button,Digit}).<br><br>init(Code) -><br> do_lock(),<br> Data = #{code => Code, remaining => Code},<br> {ok,locked,Data}.<br><br>callback_mode() -><br> state_functions.<br><br>locked(<br> cast, {button,Digit},<br> #{code := Code, remaining := Remaining} = Data) -><br> case Remaining of<br> [Digit] -><br> do_unlock(),<br> {next_state,open,Data#{remaining := Code},10000};<br> [Digit|Rest] -> % Incomplete<br> {next_state,locked,Data#{remaining := Rest}};<br> _Wrong -><br> {next_state,locked,Data#{remaining := Code}}<br> end.<br><br>open(timeout, _, Data) -><br> do_lock(),<br> {next_state,locked,Data};<br>open(cast, {button,_}, Data) -><br> do_lock(),<br> {next_state,locked,Data}.<br><br>do_lock() -><br> io:format("Lock~n", []).<br>do_unlock() -><br> io:format("Unlock~n", []).<br><br>terminate(_Reason, State, _Data) -><br> State =/= locked andalso do_lock(),<br> ok.<br>code_change(_Vsn, State, Data, _Extra) -><br> {ok,State,Data}.<br><br>_______________________________________________<br>erlang-questions mailing list<br><a ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br><br><br></div> </div> </div> </div></div></body></html>