As has been explained quite explicitly twice already, you call it as a sub
by using the full explicit name of the subroutine:

$z = infix:<+^>($x, $y)



On Sun, 19 Jan 2020 at 07:22, ToddAndMargo via perl6-users <
perl6-us...@perl.org> wrote:

> On 2020-01-18 06:09, Tobias Boege wrote:
> > On Fri, 17 Jan 2020, ToddAndMargo via perl6-users wrote:
> >> Hi All,
> >>
> >> https://docs.raku.org/routine/+$CIRCUMFLEX_ACCENT
> >>
> >> (Operators) infix +^ยง
> >>
> >> multi sub infix:<+^>($a, $b --> Int:D)
> >>
> >> Integer bitwise XOR operator: Coerces both arguments to Int and does a
> >> bitwise XOR (exclusive OR) operation.
> >>
> >>
> >> $ p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b0000_1111; my uint8 $z =
> >> +^($x, $y ); say "0", $x.base(2); say "0000", $y.base(2); say
> $z.base(2);'
> >>
> >> 01010111
> >> 00001111
> >> 11111101
> >>
> >>
> >> XOR
> >> A  B   A xor B
> >> 0  0      0
> >> 1  0      1
> >> 0  1      1
> >> 1  1      0
> >>
> >> That s not what I am seeing above.
> >>
> >> What am I doing wrong this time?
> >>
> >> And who set the high bit making $z negative?
> >>
> >
> > As was already mentioned, if you want to use the &infix:<+^> operator,
> > you have to either call it by its full name as a sub:
> >
> >    &infix:<+^>($x, $y)
> >
> > or you have to use it according to its syntax category, as an infix:
> >
> >    $x +^ $y
> >
> > When you write +^($x,$y), its cousin &prefix:<+^> is called instead,
> > because now you use +^ as a prefix operator. That one performs bitwise
> > negation on its argument coerced to Int, and since you pass it a list
> > of length two, you actually evaluate +^2. And that's how you get the
> > high bit and a value of -3.
> >
> > Regards,
> > Tobias
> >
>
> Hi Tobias,
>
> This works perfectly using the syntax $a = $b +^ $c
>
> p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b0000_1111; my uint8 $z = $x
> +^ $y; say "0", $x.base(2); say "0000", $y.base(2); say "0",$z.base(2);'
>
> 01010111    # $x
> 00001111    # $y
> 01011000    # z = x xor y
>
>
> But what is now confusing me is $c = +^( $a, $b )
>
> p6 'my uint8 $x=0b0101_0111; my uint8 $y = 0b0000_1111; my uint8 $z =
> +^($x, $y); say "0", $x.base(2); say "0000", $y.base(2); say $z.base(2);'
>
> 01010111    # $x
> 00001111    # $y
> 11111101    # z is not  x xor y
>
> Which is clearly not correct.  The manual states:
>
>        Integer bitwise XOR operator: Coerces both
>        arguments to Int and does a bitwise XOR
>        (exclusive OR) operation.
>
> In my example run line, I purposefully left the
> high bit off to keep overly helpful Raku from thinking
> I had a negative number when it annoyingly overrules
> my choice of native type.  (Ordinarily I like this
> feature, except when doing bitwise operations, I
> wish I could turn it off.)
>
> So I am confused.
>
> -T
>

Reply via email to