<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'Chapter 8 Problems' | Pragmatic Forums</title>
    <link>http://fora.pragprog.com/forums/27/topics/311</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>Chapter 8 Problems posted by Alain O'Dea @ Sun, 15 Jun 2008 17:15:53 -0000</title>
      <description>&lt;p&gt;Hi Nico,&lt;/p&gt;


	&lt;p&gt;You have an interesting and concise solution there. I like the idea of having a single different process in the ring that decrements the message number. Nice work!&lt;/p&gt;</description>
      <pubDate>Sun, 15 Jun 2008 17:15:53 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:27:311:3179</guid>
      <author>Alain O'Dea</author>
      <link>http://fora.pragprog.com/forums/27/topics/311</link>
    </item>
    <item>
      <title>Chapter 8 Problems posted by Nico Verwer @ Tue, 03 Jun 2008 20:43:50 -0000</title>
      <description>&lt;p&gt;Hello all. I did not do the second part of problem 2, because I don&amp;#8217;t have a blog. The solution I came up with is a bit different from what I have seen in blogs, so I thought I&amp;#8217;d post it here.&lt;/p&gt;


&lt;pre&gt;
-module(c8p2).
-export([start/2]).

start(Rounds, Size) -&amp;gt;
  Ring = ring(Size-1, self()),        %% Set up a ring of Size-1, because self() will participate.
  statistics(runtime),
  Ring ! {ping, Rounds},              %% Send the ping into the ring.
  main(Ring),                         %% Put myself into the ring.
  {_, Runtime} = statistics(runtime),
  io:format("Ringing ~p messages took ~p milliseconds~n", [Rounds * Size, Runtime]).

%% Create a ring of specified size. Boss is the start of the ring.
ring(1, Boss) -&amp;gt;
  spawn(fun() -&amp;gt; proc(1, Boss) end);
ring(N, Boss) -&amp;gt;
  spawn(fun() -&amp;gt; proc(N, ring(N-1, Boss)) end).

%% Proc is a process in the ring. N is its number in the ring, Next is the next process.
proc(N, Next) -&amp;gt;
  receive
    {ping, M} -&amp;gt;                      %% M is the message number.
      Next ! {ping, M},               %% Propagate the message.
      if
        M &amp;gt; 1 -&amp;gt; proc(N, Next);       %% Expect more messages.
        true -&amp;gt; ready                 %% We're done.
      end
  end.

%% Main is similar to proc, but decrements the message number.
%% Returns when all messages have been sent.
main(Next) -&amp;gt;
  receive
    {ping, M} -&amp;gt;
      if
        M &amp;gt; 1 -&amp;gt;
          Next ! {ping, M-1},
          main(Next);
        true -&amp;gt; ready
      end
  end.
&lt;/pre&gt;</description>
      <pubDate>Tue, 03 Jun 2008 20:43:50 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:27:311:3034</guid>
      <author>Nico Verwer</author>
      <link>http://fora.pragprog.com/forums/27/topics/311</link>
    </item>
    <item>
      <title>Chapter 8 Problems posted by Alain O'Dea @ Wed, 02 Apr 2008 02:59:30 -0000</title>
      <description>&lt;p&gt;I posted a reply to your blog, but it was dark and appears to have been eaten by a grue :(&lt;/p&gt;</description>
      <pubDate>Wed, 02 Apr 2008 02:59:30 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:27:311:2523</guid>
      <author>Alain O'Dea</author>
      <link>http://fora.pragprog.com/forums/27/topics/311</link>
    </item>
    <item>
      <title>Chapter 8 Problems posted by Christopher Atkins @ Tue, 11 Mar 2008 01:42:36 -0000</title>
      <description>&lt;p&gt;Hi all!  Man, I&amp;#8217;m loving Erlang.  It&amp;#8217;s nice to be excited about programming again.  Thanks &lt;span class="caps"&gt;JOE&lt;/span&gt;!!&lt;/p&gt;


	&lt;p&gt;I completed &lt;a href="http://iformattable.blogspot.com/2008/03/programming-erlang-chapter-8-problem-2.html"&gt;problem 2&lt;/a&gt;, and I was hoping someone might give me some pointers.&lt;/p&gt;</description>
      <pubDate>Tue, 11 Mar 2008 01:42:36 -0000</pubDate>
      <guid isPermaLink="false">fora.pragprog.com:27:311:2419</guid>
      <author>Christopher Atkins</author>
      <link>http://fora.pragprog.com/forums/27/topics/311</link>
    </item>
  </channel>
</rss>
