Am 16.06.19 um 16:52 schrieb Sven Schreiber:
Am 16.06.2019 um 16:03 schrieb Artur Tarassow:
> <hansl>
> scalar s = 0
> loop i=1..2 -q
> catch s = (i==1) ? 1 : +1 # no effect
> s
> catch s = (i==1) ? 1 : s++ # no effect
> s
> catch s = (i==1) ? 1 : s+1 # works as intended
> s
> endloop
> </hansl>
>
> Why is the 2nd approach not working here?
Hi Artur,
let's see: so the first loop iteration is basically redundant, because
you have i==1 and so you repeatedly assign the number 1 to s. OK. The
first assignment is also trivial, since it always assigns the number +1
(which is the same as 1 of course).
So you might as well formulate the whole thing as:
I took this rather 'absurd' example just for illustration ;-)
<hansl>
scalar s = 1
s = s++ # no effect
s
s = s + 1 # works as intended
s
</hansl>
IMHO the assignment with s++ shows _some_ bug, but I'm not sure which.
In hansl AFAIK s++ must be seen as a short form of the *assignment* s =
s+1 (or s+=1), it is not an *expression*. And in hansl you cannot have
two assignments on the same line I think. (Except in the header of a
"loop for" command.)
So I believe there are two possibilities:
1) s = s++ is legal, but not working, and thus a real bug.
2) [More likely I think...] The line is not really supported, and the
parser should show an error message; and the fact that it doesn't do
that is the bug.
Ok, thanks for your comments, Sven. Let's see what Allin and Jack say on
this.
Best,
Artur