New EEP draft: Pinning operator ^ in patterns
Richard Carlsson
carlsson.richard@REDACTED
Thu Jan 21 21:09:23 CET 2021
Den tors 21 jan. 2021 kl 18:39 skrev Sean Hinde <sean.hinde@REDACTED>:
> > This is a *complication*, not a *simplification*.
>
> This. Following along this discussion I find myself holding imaginary
> conversations with a new Erlang programmer.
>
> These conversations all end up in the weeds of why a variable can / should
> sometimes be written with a caret. For me this solves a non problem for
> folks experienced in Erlang, and provides an extra hurdle to newcomers.
>
But the complexity already exists, in the language semantics, in the
compiler and all tooling, and all books and tutorials. A newcomer must
still make a mental model of what happens when an already bound variable is
used in a pattern. The only difference is that right now, it's not very
visible, and it's sensitive to changes in lines above.
Lots of new corner cases in the learner world view to explain and
> understand and reason about.
>
There's only one case: you can use an already bound variable in a pattern,
as long as you mark it. That's it. In all patterns. And never outside a
pattern.
> I would support adding a warning for those who see matching on bound
> variables as a source of errors and not an awesome feature.
>
I agree that it's an awesome feature - which is why I'm wanting to preserve
it as much as possible while making its use totally safe and very readable.
Just warning for already bound variables would in practice mean deprecating
and switching to temp variables plus guards, with a drop in readability.
/Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210121/6c8c615b/attachment.htm>
More information about the erlang-questions
mailing list