Re: New EEP draft: Pinning operator ^ in patterns

Loïc Hoguin <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Organization Nine Nines
Message-ID <[email protected]>
On 22/01/2021 17:05, Raimo Niskanen wrote:
>> Why not discuss eliminating shadowing entirely? Is there some reason
>> this suggestion has not been addressed at all? It is a curious omission
>> given that it has been brought up multiple times.
> 
> It has been talked about, and I am for!
> 
> Oddly enough ;-) I think the pinning operator would help when removing
> shadowing:
> 
>      foo(X) ->
> 	F = fun (A, ^X) ->
> 	        {A, X}
> 	    end,
> 
> instead of
> 
>      foo(X) ->
> 	F = fun (A, X1) when X1 =:= X ->
> 	        {A, X1}
> 	    end,
> 
> I think the first is neater, since that is how you can write it in a case.
> The X is the X everywhere.  Without the pinning operator one can easlily
> miss that the ^X is a match.

I said the same in PR comments, I think it'd be a very appropriate use 
of ^. This alone is why I'm not opposed to introducing ^ as long as it 
remains optional.

-- 
Loïc Hoguin
https://ninenines.eu
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.