Google Group

Working on exercises? Exchange questions, suggestions and solutions with other readers from the Erlang Programming Google Group

Subscribe to Erlang Programming
Email:


Title: Re: Exercise 4-2: The Process Ring (continued)
Date/Time: Tue, 09 Mar 2010 08:30:30 UT
Description: Dear Hynek
Alas, I feared as much. The global variable metaphor is a good one.
Thanks for your comment and your code.
Best wishes
Ivan

Title: Re: [Erlang Programming Book] Exercise 4-2: The Process Ring (continued)
Date/Time: Mon, 08 Mar 2010 10:09:37 UT
Description: No, it is bad practice. Registered process is something like global
variable. Making atoms is bad practice too. If you can avoid it, do
it.
It can be solved in far simpler way.
-module(ring).
-export([start/3]).
start(M, N, Msg) when
is_integer(M), M > 0,
is_integer(N), N > 0 ->
First = start_ring(N, self()),

Title: Exercise 4-2: The Process Ring (continued)
Date/Time: Sun, 07 Mar 2010 22:27:28 UT
Description: Dear All
Apologies for opening a new topic. I don't seem to be able to reply
to the existing thread:
[link]
Here is my solution. I don't know if I understood the question
properly: I set up a process ring of N processes, then I send a single

Title: Re: Ch4 (p101) on receiving messages: {Pid, Msg} "not entirely secure"
Date/Time: Wed, 24 Feb 2010 10:20:29 UT
Description: Dear Hynek
Thanks for your comment. It hadn't occurred to me that some other
process could send {Pid, Msg}, but of course I can see it now. I look
forward to learning more about OTP.
Best
Ivan

Title: Re: [Erlang Programming Book] Ch4 (p101) on receiving messages: {Pid, Msg} "not entirely secure"
Date/Time: Tue, 23 Feb 2010 11:51:03 UT
Description: I think it is more about reliability than security. There is all
trusted inside VM. There are some reliability issues in go/0 snippet.
What happen if spawned process unexpectedly died? What if does not
send {Pid, Msg} at all? What if some other process sends {Pid, Msg}?
Look for gen:call/2,3 how to do it really reliably. I will do at

Title: Ch4 (p101) on receiving messages: {Pid, Msg} "not entirely secure"
Date/Time: Tue, 23 Feb 2010 10:28:55 UT
Description: Dear All
In Chapter 4 (p. 101) in the section on receiving messages, discussing
the go() receive clause ...
4 go() ->
5 Pid = spawn(echo, loop, []),
6 Pid ! {self(), hello},
7 receive
8 {Pid, Msg} ->
9 io:format("~w~n",[Msg])
10 end,
11 Pid ! stop.
... we are told that line 8's matching on a pre-defined Pid "is a good

Title: Exercise 4-1: An Echo Server
Date/Time: Thu, 11 Feb 2010 04:39:00 UT
Description: Hi,
Here's my solution for Exercise 4-1: An Echo Server.
%% Erlang Programming
%% Exercise 4-1: An Echo Server
-module(echo).
-export([start/0,print/1,stop/ 0]).
-export([loop/0]).
start() ->
register(echo, spawn(echo, loop, [])),
ok.
print(Msg) ->
echo ! {print, Msg},
ok.
stop() ->
echo ! stop,

Title: Missing diagram or typo p98?
Date/Time: Sat, 16 Jan 2010 16:00:22 UT
Description: Dear All
I think a diagram has gone astray from page 98. The fist para says,
"... contrast the bound variable Pid in figure 4-4 with the unbound
variable DigitList in figure 4-5, ..". There is a figure 4-5, but
it's not the one being referred to here.
Is there a missing figure, or could that be talking about the unbound

Title: Re: Exercise 4-2: The Process Ring
Date/Time: Mon, 04 Jan 2010 22:10:48 UT
Description: hi,
Below a solution where a central process sets up the ring and manage
it.
-module(ring).
-export([start/3, manager/0, loop/1]).
start(M, N, Message) ->
register(manager, spawn(ring, manager, [])),
io:format("Manager is ~w~n", [manager]),
manager!{create, N},
manager!{send, M, Message},
manager!{stop},

Title: Re: Chapter 3 flatten exercise -- can be identify a list via pattern matching?
Date/Time: Mon, 04 Jan 2010 22:51:58 UT
Description: You can test against the pattern [H|N]:
flatten([[H|T1]|T2]) -> concatenate([flatten([H|T1]), flatten(T2)]).
Sami