New EEP draft: Pinning operator ^ in patterns

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Jan 28 16:18:06 CET 2021


On Thu, Jan 28, 2021 at 03:35:32PM +0100, Michael P. wrote:
> On Wed, 27 Jan 2021 23:04:54 +0100
> Raimo Niskanen <raimo+erlang-questions@REDACTED> wrote:
> 
> > So have no fear, the pinning operator would not take away any feature from
> > Erlang.  Hopefully it would give clarification to newcomers; when I first
> 
> Sorry, but yes it would: its simplicity!

But it can be argued that in this case the simplicity is only apparent,
since the simplicity hides two fundamentally different cases.

So it might in fact be too simplistic now.


> 
> 
> > learned Erlang I missed some way to see the difference between binding a
> > variable in a pattern and using an already bound variable.
> 
> Is that not only the case with the match operator?

Sorry.  Please explain.

> 
> Do not all other patterns intoduce a new scope?

Binding a variable is the start of the scope for that variable.
The scope ends where the function clause ends.
Or the fun() clause.

> 
> And friend compiler already warns about any attempt
> at closure therein?

Are you talking about fun() argument shadowing here?
What about it?

> 
> The Erlang doc says:
> 
> a) "A pattern has the same structure as a term but
>     can contain unbound variables."

      Bound variables in a pattern may/should be annotated
      with a preceeding ^.

> 
> b) "A variable is an expression."
> 
> c) "An arithmetic expression can be used within a pattern [...]
>     can be evaluated to a constant when complied."
> 
> Now:
> 
> a) is incomplete, it can also contain boundies and thus, see b),

I tried to complete a) above, how does that look?

> a type of expression that contradicts c).

I wonder if b) should be "A variable (bound) is an expression".
Because unbound variables are only allowed in patterns,
not in expressions.

> 
> I would not want to add any explanation of a syntactical
> annotation to that. Not even after a cleanup, as this shows
> that it is already complicated enough.

...or that it should be explained better...

> 
> If it wasn't Erlang, I would run and hide -- and I _could_ hide ...
> 
> 
> > The pinning operator would make this distinction clear, in precisely
> > the spot where the already bound variable is used in a pattern, which is
> > the odd case that deserves highlighting.
> 
> I am working on the examples but for now: does it not simply
> _hide_ a need to rephrase to explicitness?

Awaiting examples...

> 
> By the way: Is it an operator in Elixr? If not, I would quickly
> retreat two steps from anything and anyone having to do with Elixir.

That a similar operator exists in Elixir is not in itself a valid argument
against introducing this operator in Erlang.


> 
> ~M
> 
> --
> 
> ¡Menos economia! - ¡Mas econotuya!
> 
> Less economy! - More econoyou!
> 
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list