Sunday, June 29, 2008

Erlang Ring Exercise

I didn't bother with the benchmark part, simply the implementation. This starts out like mine but the message handling seems a bit more involved. I have to say this exercise is a good one to wrap ones head around functional programming.


-module(ring).
-export([ring/3]).

ring(Proc_count, Msg_count, Msg) ->
First=spawn(fun() -> loop() end), %% first process
links(Proc_count, First, First), %% others
First ! {Proc_count * Msg_count, Msg}. %% send msg to first

links(1, First, Left) ->
First ! {left, Left}; %% tell First who his Left is (last link)

links(Proc, First, Left) ->
P=spawn(fun() -> loop(Left) end),
links(Proc-1, First, P).

loop() -> %% this loop is for First
receive
{left, Left} ->
loop(Left)
end.

loop(Left) ->
receive
{1, Msg} -> %% done
io:format("[~p]: ~p says ~p~n",[1, self(), Msg]);
{Count,Msg} -> %% send message to process on my left
io:format("[~p]: ~p says ~p~n",[Count, self(), Msg]),
Left ! {Count-1, Msg },
loop(Left)
end.

Tuesday, June 24, 2008

InfoQ: The multicore crises: Scala vs. Erlang

InfoQ: The multicore crises: Scala vs. Erlang

This language debate is really interesting and eye opening. I think Erlang will end up winning in the long term.

Monday, June 23, 2008

Ah, the perfect child companion!


armstrong on software: The Road we didn't go down

armstrong on software: The Road we didn't go down

Interesting views on RPC. This is going to make me think twice when I comment on something that just seems to be another RPC implementation (most are). I've been re-reading the Erlang book. Maybe someday I'll be payed to program with it. :)