New EEP draft: Pinning operator ^ in patterns

Kostis Sagonas kostis@REDACTED
Thu Jan 21 17:11:23 CET 2021


On 1/21/21 3:41 PM, Richard Carlsson wrote:
> Some weird code becomes obvious when annotated.
> 
> What does this line do?
> 
>      _ = [M = M:module_info(module) || M <- Needed],
> 
> Oh, it's a multi-assertion!
> 
>      _ = [^M = M:module_info(module) || M <- Needed],

I disagree.

This is _exactly_ the kind of code where you do *not* want such an 
annotation.  You want to rewrite this to something like:

   true = lists:all(fun (M) -> M =:= M:module_info(module) end, Needed),

No matching is required here.

Kostis


More information about the erlang-questions mailing list