HaloO,
Moritz Lenz wrote:
I came to this
12:51 <@moritz_> rakudo: my $x = 3; say $x, ' ', ++$x;
12:51 < p6eval> rakudo 7b81c0: OUTPUT«4 4»
12:51 <@moritz_> rakudo: my $x = 3; say $x, ' ', $x++;
12:51 < p6eval> rakudo 7b81c0: OUTPUT«4 3»
I would expect that to say '3 4' and '3 3' respectively.
This looks very counter intuitive, because it looks like the arguments
are evaluated right-to-left, not left-to-right. (It just looks like it,
it doesn't actually happen this way; using say(~$x, ....) shows that).
Then again it might be correct, because the first positional parameter
of say() (which is slurpy, but doesn't matter here) is bound to $x, and
$x changes before say() is actually called.
I would opt for a strict left to right evaluation of expressions
irrespective of precedence and associativity of operators. E.g.
my $x = 2; $x++ ** $x; should evaluate to 8 not 4. And $x ** $x++
should be 4 not 9. Also expressions like $a + $b * $c should evaluate
$a first then $b and then $c.
Is it right that the parameter binds to the variable ($x), not to the
number (3) (which would be immutable)? I'm sure that in the presence of
"is rw" the bahviour cited above would be correct, but for 'is copy' or
the default I don't see a reason for that.
Hmm, it seems to be the case that the binding is defined to be a
readonly binding to the variable. I consider this a bad thing.
We should have my $x = 1; foo($x++,$x,$x++); to call foo(1,2,2)
and not foo(1,3,2) or even foo(2,3,1). The capture creation for
the foo call should be strictly left to right and capturing the
value at that moment.
Regards, TSa.
--
"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan