Re: troubles with with base(2)
On 2020-01-20 14:17, Tobias Boege wrote: This is a truly beautiful and thoughtful thing about Raku. The more I learn about Raku, the more it astounds me. It is so well thought out, it is mesmerizing. :-)
Re: troubles with with base(2)
On 2020-01-20 14:17, Tobias Boege wrote: ^ is a junction constructor, specifically it creates a one() junction. If you want bitwise XOR use the... bitwise XOR operator +^. I left off the +. Mumble, mumble :'(
Re: troubles with with base(2)
On Mon, Jan 20, 2020 at 3:57 PM ToddAndMargo via perl6-users mailto:perl6-us...@perl.org>> wrote: Hi All, Now what am I doing wrong? my $v = 0b00101101 ^ 0b1001; say $v.base(2); one(101101, 1001) It should be 100100 Many thanks, -T On 2020-01-20 14:21, Brad Gilbert wrote: Why would you think that? The numeric binary xor operator is +^. my $v = 0b00101101 +^ 0b1001; say $v.base(2); # 100100 ^ is the junctive xor operator. my $v = 1 ^ 2 ^ 'a'; $v eq 'a'; # True $v == 1; # True $v == 2; # True $v == 3; # False There is also the stringy binary xor operator. say 'A' ~^ '%'; # D Ah poop! I forgot the + Thanks for the second pair of eye! Much better: my $v = 0b00101101 +^ 0b1001; say $v.base(2); 100100
Re: troubles with with base(2)
Why would you think that? The numeric binary xor operator is +^. my $v = 0b00101101 +^ 0b1001; say $v.base(2); # 100100 ^ is the junctive xor operator. my $v = 1 ^ 2 ^ 'a'; $v eq 'a'; # True $v == 1; # True $v == 2; # True $v == 3; # False There is also the stringy binary xor operator. say 'A' ~^ '%'; # D On Mon, Jan 20, 2020 at 3:57 PM ToddAndMargo via perl6-users < perl6-us...@perl.org> wrote: > Hi All, > > Now what am I doing wrong? > > my $v = 0b00101101 ^ 0b1001; say $v.base(2); > one(101101, 1001) > > It should be > 100100 > > > Many thanks, > -T >
Re: troubles with with base(2)
On Mon, 20 Jan 2020, ToddAndMargo via perl6-users wrote: > Hi All, > > Now what am I doing wrong? > > my $v = 0b00101101 ^ 0b1001; say $v.base(2); > one(101101, 1001) > > It should be > 100100 > Please examine the output you get. Does the spurious "one" in there not make you raise an eyebrow and head over to the documentation? ^ is a junction constructor, specifically it creates a one() junction. If you want bitwise XOR use the... bitwise XOR operator +^. In general, the "bare" operators &, |, ^ in Raku are used for declarative purposes: in normal Raku they are junction constructors and in regexes they denote longest-token matching. Many other languages use these operators for (signed or unsigned) bitwise operations, but in Raku these "numeric" bitwise operations are put under the "+" umbrella to show that they are numeric: +&, +| and +^. Corresponding operators also exist for buffers as ~&, ~| and ~^, for booleans as ?&, ?| and ?^ and for sets as (&), (|), (^). This is a truly beautiful and thoughtful thing about Raku. Regards, Tobias -- "There's an old saying: Don't change anything... ever!" -- Mr. Monk
troubles with with base(2)
Hi All, Now what am I doing wrong? my $v = 0b00101101 ^ 0b1001; say $v.base(2); one(101101, 1001) It should be 100100 Many thanks, -T