New EEP draft: Pinning operator ^ in patterns

Richard Carlsson carlsson.richard@REDACTED
Thu Jan 21 20:29:29 CET 2021


Den tors 21 jan. 2021 kl 17:12 skrev Kostis Sagonas <kostis@REDACTED>:

> 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.
>

I never said it was good code, did I? I said it was weird code, which
*exists today* in the OTP codebase, and that thanks to the annotation it at
least became more obvious what it did. Now that we see what it does, it's
easier to say "this probably ought to be rewritten". Your version isn't
great however, because when it crashes it won't reveal which M did not
match, just that one of them didn't.

        /Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210121/feca3ad4/attachment.htm>


More information about the erlang-questions mailing list