[erlang-questions] case expression scope
Thomas Lindgren
thomasl_erlang@REDACTED
Wed Mar 5 18:13:29 CET 2014
The way I see it, the feature of implicit variable matching is more trouble than it's worth. Warnings about such matches would catch this kind of problems.
For myself, it's seldom used in practice, and mostly a source of hidden bugs and unobvious code. Rewriting into explicit comparisons is normally straightforward and clearer, so having it doesn't buy me a lot. But maybe I'm being unreasonable. Anyone use bound variables in patterns a lot by intent?
Best,
Thomas
On Wednesday, March 5, 2014 4:57 PM, Anthony Ramine <n.oxyde@REDACTED> wrote:
Why would you warn for this? It’s a feature.
>
>--
>Anthony Ramine
>
>
>Le 5 mars 2014 à 16:38, Thomas Lindgren <thomasl_erlang@REDACTED> a écrit :
>
>> Occurrences of bound variables in patterns. For example A, B, C, and D in these:
>>
>> {A, B} = f(X),
>> {A, B} = f(Y), % A,B already bound
>> C = g(Z),
>> C = g(W), % C is already bound
>> {D,D} = h(V) % D is bound then matched
>>
>> Best,
>> Thomas
>>
>>
>>
>> On Wednesday, March 5, 2014 3:39 PM, Anthony Ramine <n.oxyde@REDACTED> wrote:
>> What would you like to be warned about? I don’t get it.
>>
>> --
>> Anthony Ramine
>>
>> Le 5 mars 2014 à 15:33, Thomas Lindgren <thomasl_erlang@REDACTED> a écrit :
>>
>> > Thanks Anthony, that option warns for Value in the previous example because it's exported from the case, but not for the variable match that then occurs. I'd like to see a compiler option that warned about matching (bound variables occurring in patterns), which would catch other inadvertent reuse of variable names.
>> >
>> > Best,
>> > Thomas
>> >
>> >
>> > On Wednesday, March 5, 2014 2:40 PM, Anthony Ramine <n.oxyde@REDACTED> wrote:
>> > The compile option is warn_export_vars:
>> >
>> > Causes warnings to be emitted for all implicitly exported variables referred to after the primitives where they were first defined. No warnings for exported variables unless they are referred to in some pattern, which is the default, can be selected by the option nowarn_export_vars.
>> >
>> > --
>> > Anthony Ramine
>> >
>> > Le 5 mars 2014 à 12:18, Thomas Lindgren <thomasl_erlang@REDACTED> a écrit :
>> >
>> > > In the larger scheme of things: The way I see it, the feature of implicit variable matching is more trouble than it's worth. Warnings about such matches would catch this kind of problems.
>> > >
>> >
>> >
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140305/73457c9d/attachment.htm>
More information about the erlang-questions
mailing list