Need help understanding this erlang code

I am having trouble understanding this line.

[Pid2 ! {delete, V1a}
    || {Pid1a, V1a} <- PV1a, Pid2 <- P2, Pid1a /= Pid2
  ],

Here is what I understand: nothing in front of the double pipe "||" is done repeatedly, depending on what after the double pipe. therefore, messages with the removed atom are repeated in Pid2. I know the "/ =" average inequality. I don't understand what "<-" means, and ultimately means what the whole line means.

+3
source share
3 answers

[something(X) || X <- L]- this is an understanding of the list. Lis a list of elements, and this expression creates a list of new elements, forming each element, calling something on it ().

[something(X,Y) || X <-L, Y<-M] , X Y.

[something(X) || X <-L, Expr] - . , , L, Expr X.

[something(X) || {X,..} <-L, Expr] - . , .

, , , , . , , . foreach .

:

1> [ X*2 || X <- [1,2,3] ].
[2,4,6]
2> [ X*Y || X <- [1,2], Y <- [3,4,5] ].
[3,4,5,6,8,10]
3> [ X*3 || X <- [1,2,3,4], X rem 2 == 0 ].
[6,12]
4> [ X || {a,X} <- [{a,1},{a,2},{b,3},{c,4}] ].
[1,2]

, {Pid1a, V1a} PV1a Pid2 P2, , Pid1a Pid2, {delete, V1a} 2.

+15

Erlang, , , . , , -, , Erlang :

[Pid2 ! {delete, V1a} || {Pid1a, V1a} <- PV1a, Pid2 <- P2, Pid1a /= Pid2],

:

For each item in PV1a, unpacking item to {Pid1a, V1a}
    For each Pid2 in P2
        If Pid1a /= Pid2
            Pid2 ! {delete, V1a} 

, Pid PV1a P2 delete V1a Pid2, Pid1 Pid2 Pid.

+5

< - .

LC; , , Ns.

Ns = [1,2,3,4,5,6,7,8,9].
[{X,Y,C} || X <- Ns, Y <- Ns, C <- Ns, X*X + Y*Y == C*C].

.

[{3,4,5},{4,3,5}]

What seems right:

 + 4² = 5²
9 + 16 = 25
25 = 25

Thus, an understanding of the list can be read in the same way as giving each X, Y and C that X is taken from Ns, Y is taken from Ns and C is taken from Ns, and X² + Y² is equal to C².

+1
source

Source: https://habr.com/ru/post/1720142/


All Articles