New EEP draft: Pinning operator ^ in patterns

Mikael Pettersson mikpelinux@REDACTED
Sat Jan 16 14:20:17 CET 2021


On Fri, Jan 15, 2021 at 4:36 PM Raimo Niskanen
<raimo+erlang-questions@REDACTED> wrote:
> And I want to get clarity about exactly why so many developers are worried
> about this particular proposed change, and therefore try to look thoroughly
> at the arguments.
>
> It is as you say a fundamental detail in the language.
>
> 1) Would the language be a better language with a mandatory pinning operator?
>
> 2) If so is there a migration path worth the trouble?
>
> So far I think the discussion has been centered around 2),
> before talking about 1).

I acknowledge the issue the pinning operator is trying to solve, but I
disagree with the solution, especially the syntactic noise and
special-case semantics of the operator.

I believe that a better solution is to gradually abolish the notion
that variables in patterns may refer to the surrounding scope. This
means adding "when PatVar = OtherVar" guards in the few affected
places, but those guards are already part of the language, and already
required in some contexts. That is, nothing needs to be _added_ to the
language, instead the language is simplified by having fewer special
cases in its semantics.

Migration would be a straight-forward sequence of steps mainly adding
a warning option to the compiler, at some point enabling it by
default, and eventually making it mandatory.

One issue is that the compiler _must_ still recognize the ref trick in
selective receives when expressed using "when PatVar = OtherVar"
guards. (This may or may not already be the case.)

/Mikael


More information about the erlang-questions mailing list