<html><head><meta http-equiv="Content-Type" content="text/html charset=gb2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Yes, it works with:<div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">                [</span><span style="font-variant-ligatures: no-common-ligatures; color: #cd7923" class="">Digit</span><span style="font-variant-ligatures: no-common-ligatures" class="">|</span><span style="font-variant-ligatures: no-common-ligatures; color: #cd7923" class="">Rest</span><span style="font-variant-ligatures: no-common-ligatures" class="">] -></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">                    {keep_state, </span><span style="font-variant-ligatures: no-common-ligatures; color: #cd7923" class="">Data</span><span style="font-variant-ligatures: no-common-ligatures" class="">#{remaining := </span><span style="font-variant-ligatures: no-common-ligatures; color: #cd7923" class="">Rest</span><span style="font-variant-ligatures: no-common-ligatures" class="">},</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">                     [30000, {reply, </span><span style="font-variant-ligatures: no-common-ligatures; color: #cd7923" class="">From</span><span style="font-variant-ligatures: no-common-ligatures" class="">, ok}]};</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Thanks</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">by</span></div><div class=""><div><blockquote type="cite" class=""><div class="">在 2017年12月13日,16:19,Guilherme Andrade <<a href="mailto:g@gandrade.net" class="">g@gandrade.net</a>> 写道:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class="">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 class=""><br class=""></div>Maybe the following will do the trick:<br class=""><br class=""></div>    {keep_state, Data#{remaining := Rest}, [30000, {reply,From,ok}]}<br class=""><div class=""><div class=""><br class="">[1]: <a href="http://erlang.org/doc/man/gen_statem.html#type-event_timeout" class="">http://erlang.org/doc/man/gen_statem.html#type-event_timeout</a><br class=""></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On 13 December 2017 at 08:01, by <span dir="ltr" class=""><<a href="mailto:by@meetlost.com" target="_blank" class="">by@meetlost.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">Hi,<div class=""><br class=""></div><div class="">I am trying the example on <a href="http://erlang.org/doc/design_principles/statem.html#id77558" target="_blank" class="">http://erlang.org/doc/<wbr class="">design_principles/statem.html#<wbr class="">id77558</a></div><div class="">"3.21 Complex State”</div><div class=""><br class=""></div><div class="">But I got exception below:</div><div class="">==============================<wbr class="">======</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">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" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Eshell V9.0  (abort with ^G)</span></div></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">{ok,code_lock3}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Locked</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">{ok,<0.67.0>}</span></div></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Locked</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">** exception exit: {bad_return_from_state_<wbr class="">function,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                       {keep_state,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                           #{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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                           30000,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                           [{reply,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                {<0.60.0>,#Ref<0.235851222.<wbr class="">49545217.215838>},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                ok}]}}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">     in function  gen_statem:parse_event_result/<wbr class="">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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">     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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">     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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">4> </span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">=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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">** 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">** Last event = {{call,{<0.60.0>,#Ref<0.<wbr class="">235851222.49545217.215838>}},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                 {button,1}}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">** 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">** Reason for termination = error:{bad_return_from_state_<wbr class="">function,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                   {keep_state,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                    #{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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                    30000,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                    [{reply,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                      {<0.60.0>,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                       #Ref<0.235851222.49545217.<wbr class="">215838>},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">                                      ok}]}}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">** Callback mode = [handle_event_function,state_<wbr class="">enter]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">** Stacktrace =</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">**  [{gen_statem,parse_event_<wbr class="">result,8,[{file,"gen_statem.<wbr class="">erl"},{line,1318}]},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">     {gen_statem,loop_event,6,[{<wbr class="">file,"gen_statem.erl"},{line,<wbr class="">1015}]},</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">     {proc_lib,init_p_do_apply,3,[{<wbr class="">file,"proc_lib.erl"},{line,<wbr class="">247}]}]</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span style="font-family:Helvetica;font-size:12px" class="">==============================<wbr class="">======</span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)" class=""><br class=""></div><div style="margin:0px;line-height:normal;background-color:rgb(255,255,255)" class="">I think the problem is on this:</div><div style="margin:0px;line-height:normal;background-color:rgb(255,255,255)" class=""><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)" class="">            [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)" class="">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)" class=""><pre style="font-family:mono,Courier,monospace;margin-top:0px;margin-bottom:0px" class="">          [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 class=""><br class=""></div></pre><div class="">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 class="">And, I also tried just remove the “30000”, and it works fine.</div><div class=""><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" class="">          [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 class=""><br class=""></div><div class="">My question is:</div><div class="">Is this a typo in the documentation?</div><div class="">Or</div><div class="">Am I missing something?</div><div class=""><br class=""></div><div class="">Thanks</div><span class="HOEnZb"><font color="#888888" class=""><div class="">by</div></font></span></div></div><br class="">______________________________<wbr class="">_________________<br class="">
erlang-questions mailing list<br class="">
<a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank" class="">http://erlang.org/mailman/<wbr class="">listinfo/erlang-questions</a><br class="">
<br class=""></blockquote></div><br class=""><br clear="all" class=""><br class="">-- <br class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class="">Guilherme<br class=""></div></div></div></div></div></div>
</div>
</div></blockquote></div><br class=""></div></div></body></html>