New EEP draft: Pinning operator ^ in patterns

Igor Clark igor.clark@REDACTED
Fri Jan 22 18:37:47 CET 2021


Kinda disagree, partly because from using regular expressions a lot, I find ^X just seems like "not-X" - and I guess that resonates with the exclusion-like XOR usage in other languages, too.

More importantly though, to take one of Richard's examples from his OTP scan, to me SSH1 is immediately, visibly a lot more different from SSH than ^SSH, which seems like just some special case of SSH that I have to remember. "Oh ... What did that mean again?" I really don't want to have to do that - I love the fact that Erlang doesn't make me remember any of that stuff. I guess I'd get over it in time but I'd rather not have yet more cognitive load.

Also it's been written elsewhere in the thread that  that sigils are nothing new, maps give us #{} and binaries bring in <<Var:X/binary>> and so forth. I think those are really different, they're delimiters rather than annotations, and they occur in the course of a different activity, i.e. constructing, deconstructing and recognising combined sequences of values. ^X is very much an annotation onto a variable, intended as part of the reading of program logic, and I really think it's going to interrupt comprehension flow. I can't help feeling that when someone says "this is a great place for annotations", it usually means there's an underlying problem that needs sorting out. So I'm also concerned that this annotation to X is intended to tease out some meaning that apparently isn't readily seen just by reading the code, and I would prefer enormously that the conditions which allow that hidden meaning to come into existence to be addressed rather than the symptom annotated. If that's not possible, then I'd like to get a compiler warning, 'cos that'll help me fix it quickly.

Cheers,
Igor


> On 22 Jan 2021, at 17:05, Loïc Hoguin <essen@REDACTED> wrote:
> 
> 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