<div dir="ltr"><div><div><font face="monospace, monospace">Mr. Xavier, you are absolutely right!</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">
<span style="color:rgb(34,34,34);font-family:monospace,monospace;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Thank you for pointing my error.</span><br></font></div><div><font face="monospace, monospace"><span style="color:rgb(34,34,34);font-family:monospace,monospace;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></font></div><div><font face="monospace, monospace"><span style="color:rgb(34,34,34);font-family:monospace,monospace;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Is the following flowchart closer to the truth?</span></font></div><div><font face="monospace, monospace"><span style="color:rgb(34,34,34);font-family:monospace,monospace;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><div> +-----------------+</div><div> | Enter receive. | ** Timer may have already been elapsed</div><div> | Start timer | when entering this state.</div><div> +------+----------+</div><div> |</div><div> +-----v------+ +--------------------------------+</div><div> | is mailbox | Yes | suspend process until |timer elapsed</div><div>+------> empty? +------------> a new message is put in mailbox+-----------------+</div><div>| | | | or timer has elapsed** | |</div><div>| +------------+ +-----+--------------------------+ +-------------v---------------------+ +-------------------+</div><div>| |No | |if any messages have been put into | | evaluate |</div><div>| +------v----------------+ |new msg arrived |the save queue, are reentered +-----> expressionsTimeout|</div><div>| | take the head message | | |into the mailbox | | |</div><div>| | from the mailbox <--------+ +-----------------------------------+ +--------+----------+</div><div>| +------+----------------+ |</div><div>| | +-----------------------------------+ +-------------+ |</div><div>| +-----v-------------+ +---------------+ |if any messages have been put into +----->evaluate +----------></div><div>| | match the message +---->remove message +----->the save queue, are reentered | |expressions1 | |</div><div>| | against pattern1 |Yes |from mailbox | |into the mailbox | +-------------+ |</div><div>| +-------------------+ +---------------+ +-----------------------------------+ |</div><div>| |No |</div><div>| | |</div><div>| +-----v-------------+ +---------------+ +-----------------------------------+ +-------------+ |</div><div>| | match the message +---->remove message +----->if any messages have been put into +----->evaluate +----------></div><div>| | against pattern2 |Yes |from mailbox | |the save queue, are reentered | |expressions2 | |</div><div>| +-------------------+ +---------------+ |into the mailbox | +-------------+ |</div><div>| |No +-----------------------------------+ |</div><div>| | |</div><div>| +-----v-------------+ +---------------+ +-----------------------------------+ +-------------+ |</div><div>| | match the message +---->remove message +----->if any messages have been put into +----->evaluate +----------></div><div>| | against pattern3 |Yes |from mailbox | |the save queue, are reentered | |expressions3 | |</div><div>| +-------------------+ +---------------+ |into the mailbox | +-------------+ |</div><div>| |No +-----------------------------------+ |</div><div>| | |</div><div>| +-----v------------------------------+ |</div><div>| | message is removed from the mailbox| |</div><div>+------+ and put into a "save queue" | |</div><div> | | |</div><div> +------------------------------------+ |</div><div> |</div><div> +------------------+ |</div><div> | Exit receive. <---------------------------------------------------------------------------------------------+</div><div> | Timer is cleared.|</div><div> +------------------+</div><div><br></div></font></div><div><span style="font-family:monospace,monospace"><br></span></div><div><br></div></div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 16, 2018 at 4:57 PM, Xavier Noria <span dir="ltr"><<a href="mailto:fxn@hashref.com" target="_blank">fxn@hashref.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra">I think there is a detail that does not square.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Take this example[*]:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div style="color:rgb(51,51,51);background-color:rgb(253,246,227);font-family:Hack;font-weight:normal;font-size:12px;line-height:18px;white-space:pre-wrap"><div><span style="color:rgb(51,51,51)">-</span><span style="color:rgb(133,153,0)">module</span><span style="color:rgb(51,51,51)">(</span><span style="color:rgb(38,139,210)">foo</span><span style="color:rgb(51,51,51)">).</span></div><div><span style="color:rgb(51,51,51)">-</span><span style="color:rgb(133,153,0)">export</span><span style="color:rgb(51,51,51)">([</span><span style="color:rgb(38,139,210)">start</span><span style="color:rgb(51,51,51)">/</span><span style="color:rgb(211,54,130)">0</span><span style="color:rgb(51,51,51)">]).</span></div><br><div><span style="color:rgb(38,139,210)">start</span><span style="color:rgb(51,51,51)">() </span><span style="color:rgb(133,153,0)">-></span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(38,139,210)">self</span><span style="color:rgb(51,51,51)">() </span><span style="color:rgb(133,153,0)">!</span><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(203,75,22)">matched_by_b</span><span style="color:rgb(51,51,51)">,</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(38,139,210)">self</span><span style="color:rgb(51,51,51)">() </span><span style="color:rgb(133,153,0)">!</span><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(203,75,22)">matched_by_a</span><span style="color:rgb(51,51,51)">,</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(38,139,210)">a</span><span style="color:rgb(51,51,51)">(),</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(38,139,210)">halt</span><span style="color:rgb(51,51,51)">().</span></div><br><div><span style="color:rgb(38,139,210)">a</span><span style="color:rgb(51,51,51)">() </span><span style="color:rgb(133,153,0)">-></span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(133,153,0)">receive</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(203,75,22)">matched_by_a</span><span style="color:rgb(51,51,51)"> -></span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(38,139,210)">io</span><span style="color:rgb(51,51,51)">:</span><span style="color:rgb(38,139,210)">format</span><span style="color:rgb(51,51,51)">(</span><span style="color:rgb(42,161,152)">"matched by a/0</span><span style="color:rgb(203,75,22)">~n</span><span style="color:rgb(42,161,152)">"</span><span style="color:rgb(51,51,51)">),</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(38,139,210)">b</span><span style="color:rgb(51,51,51)">()</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(133,153,0)">end</span><span style="color:rgb(51,51,51)">.</span></div><br><div><span style="color:rgb(38,139,210)">b</span><span style="color:rgb(51,51,51)">() </span><span style="color:rgb(133,153,0)">-></span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(133,153,0)">receive</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(203,75,22)">matched_by_b</span><span style="color:rgb(51,51,51)"> -></span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(38,139,210)">io</span><span style="color:rgb(51,51,51)">:</span><span style="color:rgb(38,139,210)">format</span><span style="color:rgb(51,51,51)">(</span><span style="color:rgb(42,161,152)">"matched by b/0</span><span style="color:rgb(203,75,22)">~n</span><span style="color:rgb(42,161,152)">"</span><span style="color:rgb(51,51,51)">)</span></div><div><span style="color:rgb(51,51,51)"> </span><span style="color:rgb(133,153,0)">end</span><span style="color:rgb(51,51,51)">.</span></div><br></div><br></div><div class="gmail_extra">According to your (very nice!) diagram, this program should hang, because when b/0 is invoked, the message `matched_by_b` has already been moved into the save queue, and b/0 is called <i>while</i> the expression that matches `matched_by_a` is evaluated. The diagram says `matched_by_b` is not in the mailbox at that point.</div><div class="gmail_extra"><br></div><div class="gmail_extra">But the program terminates, ergo reductio ad absurdum :).</div><div class="gmail_extra"><br></div><div class="gmail_extra">I guess that diagram comes from the algorithm outlined on page 194 of the book. I believe you need to factor in step (5).</div><div class="gmail_extra"><br></div><div class="gmail_extra">Xavier</div><div class="gmail_extra"><br></div><div class="gmail_extra">[*] erlc foo.erl && erl -noshell -run foo</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div></div>
</blockquote></div><br></div></div>