Re: New EEP draft: Pinning operator ^ in patterns
Richard Carlsson <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CANKG3zmqVf25cxUsajsF5Ckrv7rYDB2dLv+m5YJXkqqTysq+iA@mail.gmail.com> |
Den tors 21 jan. 2021 kl 18:39 skrev Sean Hinde <[email protected]>: > > 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