Dear JLG, I have another question about the time of evaluations. If I take one of the examples from the documentation, this one:
group LittleTest1 {
@local $period
let $period := 1
loop $period s {
print Now is $NOW
0.5 s let $period := $period + 1
} during [20 s]
}
It prints, as given and expected:
Now is 0
Now is 1
Now is 3
Now is 6
Now is 10
Now is 15
But when I leave out the delay of 0.5 s for changing the period (this is the only difference in LittleTest2), it prints instead:
Now is 0
Now is 2
Now is 5
Now is 9
Now is 14
The actual periods are thus not 1, 2, 3, 4, 5, but instead 2, 3, 4, 5. (In reality, 0 is something like 173.035384, of course.) I assumed that the period is evaluated before entering the body of the loop but this hasn’t proved true. It seems rather that this is done after evaluating and scheduling the action sequence. So, if there are actions without delay, they’re executed before scheduling the next iteration.
This is somewhat counter-intuitive to the position of the period specification at the beginning of the loop construct. It would be helpful to have a hint in the documentation, that the period should be changed inside the loop body only with a delay, be it a very small one, to not interfere with the scheduling of the next iteration.
Or can it be considered good style to begin with a period of 0? E.g.
group LittleTest3 {
@local $period
let $period := 0
loop $period s {
print Now is $NOW
let $period := $period + 1
} during [20 s]
}
At least, it works, printing:
Now is 0
Now is 1
Now is 3
etc.
This style is more or less equivalent to a syntax like
loop {
let $period := $period + 1
} with [$period s] during [20 s]
which I would consider a little more intuitive (for the innocent composer).