New EEP draft: Pinning operator ^ in patterns

Michael P. empro2@REDACTED
Thu Jan 28 15:35:32 CET 2021


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!


> 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?

Do not all other patterns intoduce a new scope?

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

The Erlang doc says:

a) "A pattern has the same structure as a term but
    can contain unbound variables."

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),
a type of expression that contradicts c).

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.

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?

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.

~M

--

¡Menos economia! - ¡Mas econotuya!

Less economy! - More econoyou!




More information about the erlang-questions mailing list