New EEP draft: Pinning operator ^ in patterns

Michael Truog mjtruog@REDACTED
Mon Dec 28 02:36:54 CET 2020


On 12/27/20 3:39 PM, Richard O'Keefe wrote:
>
> One thing I *would* like is an analogue of -Werror.
We have the option warnings_as_errors, so we have that now (added in 
R13B04).

Best Regards,
Michael


>
>
> On Sun, 27 Dec 2020 at 02:16, Anthony Ramine <n.oxyde@REDACTED 
> <mailto:n.oxyde@REDACTED>> wrote:
>
>     That's already a thing in Erlang and AFAIK that never caused
>     issues for anyone.
>
>     X = 2.
>     F = fun (<<_:X/binary>>, X) -> oh end.
>     F(<<0, 0>>, 3).
>
>     > Le 25 déc. 2020 à 23:41, Richard O'Keefe <raoknz@REDACTED
>     <mailto:raoknz@REDACTED>> a écrit :
>     >
>     > "This fills a much-needed gap."
>     >
>     > Erlang functions are as a rule small enough that you
>     > shouldn't ever shadow a variable.  One of the worst
>     > features of Erlang is that you can write
>     >    foo(X) -> fun (X) -> fun (X) -> 1 end end.
>     > and have three different variables all called X, and
>     > one of the good things about erlc is that it tells you.
>     > foo.erl:3: Warning: variable 'X' is unused
>     > foo.erl:3: Warning: variable 'X' is unused
>     > foo.erl:3: Warning: variable 'X' shadowed in 'fun'
>     > foo.erl:3: Warning: variable 'X' shadowed in 'fun'
>     >
>     > The very last thing we want is a notation that lets
>     > us have two different variables with the same name
>     > in a single pattern.
>     >
>     >
>     > On Fri, 25 Dec 2020 at 09:10, Richard Carlsson
>     <carlsson.richard@REDACTED <mailto:carlsson.richard@REDACTED>>
>     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
>
>
> _______________________________________________
> eeps mailing list
> eeps@REDACTED
> http://erlang.org/mailman/listinfo/eeps

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20201227/706ed4cd/attachment.htm>


More information about the erlang-questions mailing list