Tonio's Dev blog

Wednesday, November 25, 2009

I'm reading the Programming Erlang book by Joe Armstrong, and here is my own version of the 8.11.2 exercise solution. There are many available on the internet, and mine is definitively not more brillant than another.
The ring:benchmark/3 function creates a process ring of size N, sends M messages in the ring, and each of those messages will be passed around K times before being sen back to the sender.

The book is really good, it has been a long time since I had so much fun learning a new language.


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

init(N) ->
FirstPid = spawn(fun() -> waitpid(N+1) end),
init(N,FirstPid,FirstPid).

init(0,Pid,FirstPid) ->
FirstPid ! Pid;
init(N,PrevPid,FirstPid) ->
NextPid = spawn(fun() -> ring_node(PrevPid,N) end),
init(N-1,NextPid,FirstPid).

waitpid(N) ->
receive
Pid ->
ring_node(Pid,N)
end.

ring_node(Pid,N) ->
receive
{Origin, 0, Value} ->
Origin ! Value,
ring_node(Pid,N);
{Origin, Ttl, Value} ->
Pid ! {Origin, Ttl-1, Value},
ring_node(Pid,N);
Other ->
io:format("Wrong message: ~w~n", [Other]),
ring_node(Pid,N)
end.

send(Ring,Pid,M,Message) ->
Ring ! {Pid, M, Message}.
benchmark(N,M,K) ->
Pid = init(N),
My = self(),
statistics(runtime),
statistics(wall_clock),
for(1,M,fun(I) -> send(Pid,My,K,{a,I}) end),
R = getresult([],M),
{_, T1} = statistics(runtime),
{_, T2} = statistics(wall_clock),
io:format("Time spent: system:~w, clock:~w~n",[T1,T2]),
R.

getresult(L,0) ->
L;
getresult(L,M) ->
receive
Value -> getresult([Value|L],M-1)
end.

for(N,N,F) -> [F(N)];
for(Y,N,F) -> [F(Y),for(Y+1,N,F)].


Note to self: I should learn how to insert code with some colors and stuff one day.

Labels: , ,

Monday, July 09, 2007

Tom 2.5 is finally out !

We tagged the release today, and prepared all the stuff for the release. thanks to Radu, we now even have an automatic installer for Windows. Now, we need to announce it to the whole world, before starting to refactor/break/enhance everything for tom 2.6, and integrate all the new ideas.

The release notes are at there.

Labels: ,

Saturday, April 07, 2007

This week, Pierre-Etienne suggested that we should try Cenqua Clover (http://www.cenqua.com/clover/) for Tom.

Once integrated into our build system, this code coverage tool gives many useful advices.
I wasn't convinced that code coverage can be useful, but after testing it, now I am.
Running the Tom test suite and some examples build shows many things we do not really test at all, and spots areas of improvement.

Thursday, February 01, 2007

This week-end, i decided (slightly influenced by Pierre-Étienne) to implement a new and shiny feature in Gom: the possiblility to specify packages in module names.

This feature in cool, as it removes the need to use a compilation option to integrate the Gom data structure in a project: you simply have to name your module accordingly to the package.

Previously, to place the module "Peano" in the "classical" package, we had to write the Peano module in a file, Peano.gom

module Peano
abstract syntax
Nat = zero() | suc(n:Nat)

and then to compile it with gom -p classical Peano.gom

Then, for each gom file in a project, the call was different ! That's not fun if you are used to javac.
Now, we simply write

module classical.Peano
abstract syntax
Nat = zero() | suc(n:Nat)

and compile it with gom Peano.gom

Once prepared to implement that, found what to change in the design, and all, i simply read the Changelog, and found the entry

2006-11-04 tonio
* src/tom/gom/parser/:
- add support for qualifier module names
the module "dir.mod" is similar to the declaration
of a module "mod" compiled with "--package dir" option

I'm not sure I should add a new entry simply because I thought about implementing that a second time.

Tuesday, November 14, 2006

My work environment

And the most important: a great keyboard (thanks pem)

Source code analysis

I just saw an analysis of the different languages used in the Kaffe project, at http://supreetsethi.net/drupal/node/103



I wish we could have something like that for Tom. I guess it would show we have nearly no make files, very few ant scripts, and keep concentrate our efforts on Tom itself

Saturday, November 11, 2006

Setting up cia again for tom

I just added the post-commit hooks for cia to the svn repository of Tom.

That was pretty easy, except that it seems gforge does not support xml-rpc, and I had to let the cia-bot script fall back to hte old email technique.

Here is the stat page for tom: http://cia.navi.cx/stats/project/tom

Monday, November 06, 2006

subversion, encore

Bon, enfin, on arrive a avoir un dépot subversion qui fonctionne.

cvs2svn se plantait un peu sur les fichiers binaires, on a du refaire tous les imports en utilisant

cvs2svn --dump-only --keywords-off --no-default-eol ~/cvsroot

pour avoir un dépot correct

Donc maintenant, pour obtenir tom, on peut (et doit) faire:

svn co svn+ssh://login@scm.gforge.inria.fr/svn/tom/jtom/trunk jtom

Switching Tom to subversion

Today we decided to switch tom from cvs to subversion.

The expected gain is the ability to easily move things around, and also use diff in disconnected mode.
As branchs are easy to use with subversion, i hope we will soon begin to use branches for our development

The switch was not as easy as we thought, to get a correct layout of the repository, but cvs2svn helped a lot.

The new repository should be available tonight !