[erlang-questions] Can we change the semantics of matchexpressions in comprehensions?

Paulo Sérgio Almeida <>
Mon Feb 4 22:44:34 CET 2008


Matthew Dempsky wrote:
> It occurs to me now that I can just rewrite "Pat = Expr" as "Pat <-
> [Expr]" without needing to change semantics at all.  I think it might
> still be worth investigating changes along those I described, but I
> withdraw my advocacy for them for the time being.

I also happened to want such a feature and then discovered this 
work-around. However, even if it is not strictly needed, it would make 
the code clearer. I started using the hack quite frequently, and 
sometimes it is not pleasant reading the code.

   IndexEnv = [{Var, Val} ||
               Var <- IndexVars,
               {value, {_, Val}} <- [lists:keysearch(Var, 1, Env)]],

is not so bad, but it gets worse when Expr returns itself a list, e.g.

       PosVars = lists:umerge([lists:sort(Vars) ||
                                 PVVL <- PVVLs,
                                 Vars <- [[Var || {Var, _} <- PVVL]]]),

Regards,
Paulo



More information about the erlang-questions mailing list