On 2020-01-18 13:11, Marcel Timmerman wrote:
my $a=2; my $b=3; my $c = +($a, $b)
Here is the mistake that + in front of a list means (...).elems (also
used as a prefix, not infix), so there are 2 items in the list which is
true. So '+(1,2,3)' returns 3 and '+(^10)' is 10 and '+(5..10)' returns 6
To do it right one can call 'infix:<+>(2, 3)' which returns 5.
Hi Marcel,
My mistake was thinking the "infix" was a description of
a sub, not actually part of the name:
my $a=0b10; my $b=0b11; my $c = infix:<+>($a, $b); say $c.base(2);
101
The word "infix" is on eof those unicorn word that
has no meaning to me. I need to change that.
But the easy way is of course '2 + 3'.
1+ Oh no fooling!
2
And a participation trophy for the wrong answer.
my $a=2; my $b=3; my $c = +^($a, $b)
-3
Here you are using it as a prefix too, which means bitwise negation on
anything what follows. The definition however is an infix so us it as
'infix:<+^>(0b101, 0b010)' which returns 7. However it is easier to
write '0b101 +^ 0b010' or the XOR of two numbers.
2+
See also: https://docs.raku.org/routine/+ and
https://docs.raku.org/routine/+$CIRCUMFLEX_ACCENT
Same mistake again. Dang! At least I am
consistent.
And Double Dang! I guess I won't be seeing my
participation trophy any time soon.
:'(
Thank you for the excellent explanation/technical writing!
-T