inkporter
inkporter copied to clipboard
Please, use English on the source code
I see that the source code is written with many many comments in a language I do not understand. In general software development is done in English so that a broader number of people can participate.
I thought the same while re-doing the exercise on my own. The only thing I didn't like was having a hanging receive on a branch while the other one may have already finished. The solution I came up with is a little more verbose, but exploiting pattern matching it becomes easier to read and reason about, while keeping the branchy interface the same.
waitBranches(Left, Right, nil, nil) ->
receive
{Left, V} -> waitBranches(Left, Right, V, nil);
{Right, V} -> waitBranches(Left, Right, nil, V)
end;
waitBranches(Left, Right, LVal, RVal) ->
receive
{Left, V} -> {V, RVal};
{Right, V} -> {LVal, V}
end.
branchy(F, Left, Right) ->
receive
{ask, P} ->
Left ! {ask, self()},
Right ! {ask, self()},
{LVal, RVal} = waitBranches(Left, Right, nil, nil),
P ! {self(), F(LVal, RVal)}
end.
Edit: Changed code according to https://github.com/riccardotommasini/ppl/issues/10#issuecomment-356995756
I like it a lot more, can I include this code in the repository?
@leonardoarcari you need to swap :) (if I'm getting that right...)
waitBranches(Left, Right, LVal, RVal) ->
receive
{Left, V} -> {V, RVal};
{Right, V} -> {LVal, V} <-------
end.
As for me, no problem with using my code :)
@DavideSampietro Sure thing! Thanks!