New EEP draft: Pinning operator ^ in patterns
Thu Jan 21 21:28:45 CET 2021
> On 21 Jan 2021, at 21:09, Richard Carlsson <carlsson.richard@REDACTED> wrote:
> 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.
Beginners writing such large functions they fall into the trap of variable re-use from far above the match would receive the wrong lesson though - they should take this as an indication to make their functions smaller rather than be encouraged to just make big functions littered with carets.
The change of culture resulting from this change could reduce the overall quality of Erlang code.
> 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.
Not to someone just learning a language though. Until a decent level of understanding starts to arrive everything can feel like it's potentially a corner case.
> 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.
Well, I would leave the warning switched off :)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions