[erlang-questions] : Human readable errors in lists module

Raimo Niskanen <>
Fri Feb 13 10:07:23 CET 2009


On Fri, Feb 13, 2009 at 09:32:30AM +0100, Ulf Wiger (TN/EAB) wrote:
> Zvi skrev:
> > I think instead of "fixing" lists:zipwith, it's better to add
> > parallel list comprehensions, i.e.:
> > 
> > lists:zipwith(F, Xs, Ys) = [F(X,Y) || X<-Xs ; Y<-Ys].
> > 
> > Note ";" instead of ",".
> 
> 
> This is actually more difficult than it seems
> at first glance.
> 

Is not the suggestion that lists run in parallel, not execution.
I.e in contrast to
    [F(X,Y) || X <- Xs, Y <- Ys] that will create
a list of the result of calling F(X,Y) for every
combination of X and Y from the lists Xs and Ys,
    [F(X,Y) || X <- Xs; Y <- Ys] would only call
F(X,Y) for every pair X, Y from the same
position in Xs and Ys, respectively.

    f(F, Xs, Ys) -> [F(X,Y) || X <- Xs, Y <- Ys].
<=>
    f(F, Xs, Ys) ->      ff(F, Xs, Ys).
    ff(F, [X|Xs], Ys) -> fff(F, X, Ys);
    ff(_, [], _) ->      [].
    fff(F, X, [Y|Ys]) -> [F(X,Y)|fff(F, X, Ys)];
    fff(_, _, []) ->     [].

whereas

    f(F, Xs, Ys) -> [F(X,Y) || X <- Xs; Y <- Ys].
<=>
    f(F, [X|Xs], [Y|Ys]) -> [F(X,Y)|f(F, Xs, Ys);
    f(_, [], []) ->         [].

just like lists:zipwith/3.

I think it is a neat idea to achieve a lists:zipwith/2..
but I do not know if it would work syntactically.
Also, there will be arguments that a variant that
produces a result list with the length of the shortest
contributor is also desired, or prefered. So, to have
this (list zip) as syntax may be to overdo things.



> I went through parallelization of lists:map/2
> as an exercise in a recent presentation:
> 
> http://ulf.wiger.net/weblog/wp-content/uploads/2009/01/damp09-erlang-multicore.pdf
> 
> The things that need careful consideration are
> side-effects and exceptions. It's not obvious how
> a generic implementation should behave, as there is
> a cost/safety tradeoff.
> 
> BR,
> Ulf W
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list