<div dir="ltr"><div><div>It seems to be a typo. I believe the intention is to set up an event timeout[1] of 30 seconds, but if so then the timeout interval should be bundled with the call reply  - "{reply,From,ok}" - in order to make it a part of the list of actions to perform.<br><br></div>Maybe the following will do the trick:<br><br></div>    {keep_state, Data#{remaining := Rest}, [30000, {reply,From,ok}]}<br><div><div><br>[1]: <a href="http://erlang.org/doc/man/gen_statem.html#type-event_timeout">http://erlang.org/doc/man/gen_statem.html#type-event_timeout</a><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 13 December 2017 at 08:01, by <span dir="ltr"><<a href="mailto:by@meetlost.com" target="_blank">by@meetlost.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi,<div><br></div><div>I am trying the example on <a href="http://erlang.org/doc/design_principles/statem.html#id77558" target="_blank">http://erlang.org/doc/<wbr>design_principles/statem.html#<wbr>id77558</a></div><div>"3.21 Complex State”</div><div><br></div><div>But I got exception below:</div><div>==============================<wbr>======</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">Eshell V9.0  (abort with ^G)</span></div></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">1> c(code_lock3).</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">{ok,code_lock3}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">2> code_lock3:start_link([1,2,3], 4).</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">Locked</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">{ok,<0.67.0>}</span></div></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">3> code_lock3:button(1).</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">Locked</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">** exception exit: {bad_return_from_state_<wbr>function,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                       {keep_state,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                           #{code => [1,2,3],remaining => [2,3]},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                           30000,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                           [{reply,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                {<0.60.0>,#Ref<0.235851222.<wbr>49545217.215838>},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                ok}]}}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">     in function  gen_statem:parse_event_result/<wbr>8 (gen_statem.erl, line 1318)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">     in call from gen_statem:loop_event/6 (gen_statem.erl, line 1015)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">     in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 247)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">4> </span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">=ERROR REPORT==== 13-Dec-2017::15:46:09 ===</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">** State machine code_lock3 terminating</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">** Last event = {{call,{<0.60.0>,#Ref<0.<wbr>235851222.49545217.215838>}},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                 {button,1}}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">** When server state  = {{locked,4},#{}}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">** Reason for termination = error:{bad_return_from_state_<wbr>function,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                   {keep_state,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                    #{code => [1,2,3],remaining => [2,3]},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                    30000,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                    [{reply,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                      {<0.60.0>,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                       #Ref<0.235851222.49545217.<wbr>215838>},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">                                      ok}]}}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">** Callback mode = [handle_event_function,state_<wbr>enter]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">** Stacktrace =</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">**  [{gen_statem,parse_event_<wbr>result,8,[{file,"gen_statem.<wbr>erl"},{line,1318}]},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">     {gen_statem,loop_event,6,[{<wbr>file,"gen_statem.erl"},{line,<wbr>1015}]},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">     {proc_lib,init_p_do_apply,3,[{<wbr>file,"proc_lib.erl"},{line,<wbr>247}]}]</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures"><span style="font-family:Helvetica;font-size:12px">==============================<wbr>======</span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><br></div><div style="margin:0px;line-height:normal;background-color:rgb(255,255,255)">I think the problem is on this:</div><div style="margin:0px;line-height:normal;background-color:rgb(255,255,255)"><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px;color:rgb(56,58,66);font-size:11.199999809265137px;background-color:rgb(250,250,250)">               [Digit|Rest] -> <span class="m_-7374154051764026708hljs-comment" style="color:rgb(160,161,167);font-style:italic">% Incomplete</span>
                    {keep_state, Data#{remaining := Rest, <span class="m_-7374154051764026708hljs-number" style="color:rgb(152,104,1)">30000</span>},
                     [{reply,From,ok}]};</pre><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px;color:rgb(56,58,66);font-size:11.199999809265137px;background-color:rgb(250,250,250)">Change code to below got the **exception</pre><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px;color:rgb(56,58,66);font-size:11.199999809265137px;background-color:rgb(250,250,250)"><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px">           [Digit|Rest] -> <span class="m_-7374154051764026708hljs-comment" style="color:rgb(160,161,167);font-style:italic">% Incomplete</span>
                    {keep_state, Data#{remaining := Rest}, 30000,
                     [{reply,From,ok}]};</pre><div><br></div></pre><div>Actually, this is apparently wrong, since the map can not got “30000" in this case. I tried move “30000" out of the map, then the above exception occurs.</div><div>And, I also tried just remove the “30000”, and it works fine.</div><div><pre style="color:rgb(56,58,66);font-size:11.199999809265137px;background-color:rgb(250,250,250);font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px">                [Digit|Rest] -> <span class="m_-7374154051764026708hljs-comment" style="color:rgb(160,161,167);font-style:italic">% Incomplete</span>
                    {keep_state, Data#{remaining := Rest},
                     [{reply,From,ok}]};</pre></div><div><br></div><div>My question is:</div><div>Is this a typo in the documentation?</div><div>Or</div><div>Am I missing something?</div><div><br></div><div>Thanks</div><span class="HOEnZb"><font color="#888888"><div>by</div></font></span></div></div><br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Guilherme<br></div></div></div></div></div></div>
</div>