<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="">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" class="">http://erlang.org/doc/design_principles/statem.html#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="">====================================</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_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.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/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.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_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.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_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_result,8,[{file,"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=""> {gen_statem,loop_event,6,[{file,"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=""> {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,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="">====================================</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="hljs-comment" style="color: rgb(160, 161, 167); font-style: italic;">% Incomplete</span>
{keep_state, Data#{remaining := Rest, <span class="hljs-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="hljs-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="hljs-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><div class="">by</div></div></body></html>