New EEP draft: Pinning operator ^ in patterns

Loïc Hoguin essen@REDACTED
Fri Jan 22 18:05:30 CET 2021


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


More information about the erlang-questions mailing list