New EEP draft: Pinning operator ^ in patterns

Leonard B leonard.boyce@REDACTED
Thu Jan 28 00:07:29 CET 2021


On Wed, Jan 27, 2021, 16:48 Michael P. <empro2@REDACTED> wrote:

> On Thu, 14 Jan 2021 13:13:54 -0500
> Leonard B <leonard.boyce@REDACTED> 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.
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210127/1250628b/attachment.htm>


More information about the erlang-questions mailing list