Re: New EEP draft: Pinning operator ^ in patterns

Nalin Ranjan <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CACE+zkJqDqrLLjrvr2dyuoMxw_pVdFQu4A0YqHgFYXv=B5A4Cg@mail.gmail.com>
And exactly the opposite in the following case.

#!/usr/local/bin/escript
%% -*- erlang -*-

-define(SOME_MACRO(Y), X = Y + 1).

main(_Args) ->
    X = 14,
    ?SOME_MACRO(X).

On Thu, Jan 28, 2021 at 4:37 AM Leonard B <[email protected]>
wrote:

>
>
> On Wed, Jan 27, 2021, 16:48 Michael P. <[email protected]> wrote:
>
>> On Thu, 14 Jan 2021 13:13:54 -0500
>> Leonard B <[email protected]> wrote:
>>
>> > IE, if a variable is previously assigned within the outer scope use
>> > that variable within the inner scope.
>> > This, in my addled mind, makes more sense
>> >
>> > EG:
>> > %% X is from outer scope, L is from outer scope, V is local to
>> comprehension
>> > X = 5.
>> > L = [1,2,3,4,5].
>> > [V || {X, V} <- L].
>>
>> Done?
>>
>
> This was a broken example. Excuse formatting, on mobile. Should have been.
>
> > EG:
> > %% X is from outer scope, L is from outer scope, V is local to
> comprehension
> > X = 5.
> > L = [{1, a}, {2,b}, {3,c}, {4,d}, {5,e}].
> > [e] =:= [V || {X,V} <- L].
>
> What I was getting at is that for many newcomers the scoping of X is a
> surprise. I'm totally fine with this, and that possibly injecting variables
> from outer to inner scopes would be more 'logical'.
>
> Changing how scoping worked would probably be a huge change and have worse
> issues. It's just that in my mind I look at the eep and I personally see it
> boiling down to scoping.
>
> ```
>> Eshell V10.2.4  (abort with ^G)
>> 1> X = 5.
>> 5
>> 2> L = [1,2,3,4,5].
>> [1,2,3,4,5]
>> 3> [V || {X, V} <- L].
>> []
>> 4> [{X, V} || V <- L, V /= X].
>> [{5,1},{5,2},{5,3},{5,4}]
>>
>> 5> Lt = [{1, 2}, {2, 3}, {4, 5}, {5, 6}, {6, 7}, {5, 8}].
>> [{1,2},{2,3},{4,5},{5,6},{6,7},{5,8}]
>> 6> [V || {X, V} <- Lt].
>> [2,3,5,6,7,8]
>> 7> [V || {Selector, V} <- Lt, Selector == X].
>> [6,8]
>> ```
>> Names should be swapped (X, Selector).
>>
>> Naming is a burden; but also an opportunity.
>>
>> ~M
>>
>> --
>>
>> Corporation-independent Public Broadcasting is the best innovation
>> since someone said, that the volcano will erupt anyway or not, no
>> matter how many virgins are thrown into it or not.
>>
>> Unternehmensunabhängiger Öffentlich-rechtlicher Rundfunk ist
>> die beste Innovation, seit jemand sagte, dass der Vulkan eh
>> ausbricht oder nicht, egal wieviele Jungfrauen man da reinwirft
>> oder nicht.
>>
>>
>>
>>
>>
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.