My understanding of forall
statements is that they are executed in parallel, while for
statements are executed in serial. Indeed, the following code seems to confirm this expectation (i.e., a random sequence only for forall
because of threading):
for i in 1..5 do writeln( i * 10 );
10
20
30
40
50
forall i in 1..5 do writeln( i * 10 );
10
50
20
30
40
On the other hand, if I use forall
(or equivalent [...]) on the right-hand side as an expression
var A = ( forall i in 1..5 do i * 10 );
var B = [ i in 1..5 ] i * 10;
var X = ( forall a in A do a );
var Y = [ a in A ] a;
var P = ( for i in 1..5 do i * 10 ); // for comparison
writeln( "A = ", A );
writeln( "B = ", B );
writeln( "X = ", X );
writeln( "Y = ", Y );
writeln( "P = ", P );
all the results become the same (i.e., ordered from 10 to 50):
A = 10 20 30 40 50
B = 10 20 30 40 50
X = 10 20 30 40 50
Y = 10 20 30 40 50
P = 10 20 30 40 50
Does this mean that forall
expressions on the right-hand side of assignment are always executed in serial? If so, is the corresponding [...] also equivalent to for
expressions in this context?