New EEP draft: Pinning operator ^ in patterns

Michael Truog mjtruog@REDACTED
Fri Dec 25 06:05:03 CET 2020


In Elixir syntax, with variables getting rebound in all source code it 
makes sense that Elixir needs the pin operator ( ^ ) to say "Hey, this 
is different, this isn't the imperative programming variable assignment 
[match] you are accustom to!".

Erlang is different, with clearly immutable variable data.  A consistent 
variable name in the source code without a syntactic sugar ^ prefix 
helps to prevent extra work changing unrelated source code in the future 
as source code changes.  The variable name is always referred to as the 
same name in the same way, to refer to the same data.  That sameness 
helps developers understand the source code and adding a prefix would 
obscure the variable name while attempting to communicate that matching 
on a variable is somehow different from normal, though it is very normal 
in Erlang.

Matching is very important in Prolog too, with Erlang syntax being 
naturally similar.  A pin operator hasn't been necessary in Prolog 
syntax, though the matching gets more complex in Prolog (solving rubik's 
cubes with short examples and other amazing things). There isn't a clear 
benefit to adding the Elixir pin operator to Erlang, just like there 
wouldn't be a benefit to adding it to Prolog.

Best Regards,
Michael

On 12/24/20 12:10 PM, Richard Carlsson wrote:
> The ^ operator allows you to annotate already-bound pattern variables 
> as ^X, like in Elixir. This is less error prone when code is being 
> refactored and moved around so that variables previously new in a 
> pattern may become bound, or vice versa, and makes it easier for the 
> reader to see the intent of the code.
>
> See also https://github.com/erlang/otp/pull/2951
>
> Ho ho ho,
>
>         /Richard & the good folks at WhatsApp

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20201224/592d9200/attachment.htm>


More information about the erlang-questions mailing list