New EEP draft: Pinning operator ^ in patterns
Michael P.
empro2@REDACTED
Wed Jan 27 22:48:26 CET 2021
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?
```
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.
More information about the erlang-questions
mailing list