<div dir="ltr"><font face="monospace, monospace">I think the timer should also be cleared in an earlier step.</font></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 16, 2018 at 7:37 PM, Athanasios Valsamakis <span dir="ltr"><<a href="mailto:athanasios.valsamakis@gmail.com" target="_blank">athanasios.valsamakis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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"><span class=""><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------+            +-----------------------------<wbr>---+</div></span><span class=""><div>       | is mailbox | Yes        | suspend process until          |timer elapsed</div></span><div>+------> empty?     +------------> a new message is put in mailbox+-----------------+</div><div>|      |            |            | or  timer has elapsed**        |                 |</div><div>|      +------------+            +-----+-----------------------<wbr>---+   +-------------v--------------<wbr>-------+     +-------------------+</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      <--------+                              +-----------------------------<wbr>------+     +--------+----------+</div><div>|     +------+----------------+                                                                                          |</div><div>|            |                                        +-----------------------------<wbr>------+     +-------------+          |</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>|      +-------------------+    +---------------+     +----------------------------<wbr>-------+                              |</div><div>|            |No                                                                                                         |</div><div>|            |                                                                                                           |</div><div>|      +-----v-------------+    +---------------+     +----------------------------<wbr>-------+     +-------------+          |</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                                      +-----------------------------<wbr>------+                              |</div><div>|            |                                                                                                           |</div><div>|      +-----v-------------+    +---------------+     +----------------------------<wbr>-------+     +-------------+          |</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                                      +-----------------------------<wbr>------+                              |</div><span class=""><div>|            |                                                                                                           |</div><div>|      +-----v-----------------------<wbr>-------+                                                                            |</div><div>|      | message is removed from the mailbox|                                                                            |</div><div>+------+ and put into a "save queue"        |                                                                            |</div><div>       |                                    |                                                                            |</div><div>       +----------------------------<wbr>--------+                                                                            |</div><div>                                                                                                                         |</div><div>        +------------------+                                                                                             |</div></span><div>        | Exit receive.    <-----------------------------<wbr>------------------------------<wbr>------------------------------<wbr>----+</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><div class="h5"><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></div></div>
</blockquote></div><br></div>