Re: my keeper on bitwise operations

2020-01-19 Thread ToddAndMargo via perl6-users

On 2020-01-19 05:17, Mark Senn wrote:

Bitwise += / ~=:  Put and "=" after the bitwise operator:


s/and/an/?

Mark Senn, Senior Software Engineer,
Engineering Computer Network, Purdue University
technical editor for four Perl 5 books


Hi Mark,

Oops.  Thank you!

I think I also have some Perl 5 examples
in there labeled Perl 6.

:'(

-T


Re: my keeper on bitwise operations

2020-01-18 Thread ToddAndMargo via perl6-users

On 2020-01-18 16:26, Elizabeth Mattijsen wrote:

On 19 Jan 2020, at 01:15, ToddAndMargo via perl6-users  
wrote:
alias p5='perl6 -E'


s/perl6/perl/




Great catch.  Thank you!

Perl: bitwise operators:

alias p5='perl -E'
alias p6='perl6 -e'




--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: my keeper on bitwise operations

2020-01-18 Thread Elizabeth Mattijsen
> On 19 Jan 2020, at 01:15, ToddAndMargo via perl6-users  
> wrote:
> alias p5='perl6 -E'

s/perl6/perl/


my keeper on bitwise operations

2020-01-18 Thread ToddAndMargo via perl6-users

Hi All,

My keeper on bitwise operations:

-T



Perl: bitwise operators:

alias p5='perl6 -E'
alias p6='perl6 -e'


Shift Left and OR:
$ p6 'my Buf $x=Buf.new(0xAE,0x5D,0x5C,0x72);
  my int32 $i=$x[3] +< 0x18  +|  $x[2] +< 0x10  +|  $x[1] +< 
0x08  +|  $x[0];

  say $x; say $i.base(0x10);'

  Buf:0x
  725C5DAE


Bitwise += / ~=:  Put and "=" after the bitwise operator:

$ p6 'my int32 $i=0x5DAE; say $i.base(0x10); $i +<= 0x01; say 
$i.base(0x10);'

5DAE
BB5C

$ p6 'my $v = 0b0010; $v +|= 0b00010001; say $v;'
49

$ p6 'my $v = 0b0010; $v +|= 0b00010000; say $v;'
48


Bitwise AND:
$ p6 'my $v = 32 +& 16; say $v;'
0

$ p5 'my $v = 32 & 16; say $v;'
0


Bitwise OR (note +|= example):
$ p5 'my $v = 32 | 16; say $v;'
48

$ p6 'my $v = 32 +| 16; say $v;'
48

$ p6 'my $v = 0b0010; $v +|= 0b00010001; say $v;'
49

$ p6 'my $v = 0b0010; $v +|= 0b00010000; say $v;'
48


Bitwise shift left:
$ p6 'my $v = 0b0100 +< 2; say $v;'
16

$ p5 'my $v = 0b0100 << 3; say $v;'
32



Bitwise shift right:
$ p5 'my $v = 0b00010100 >> 3; say $v;'
32

$ p6 'my $v = 0b00110100 +> 3; say $v;'
6


Bitwise XOR:
$ p6 'my $v = 0b00101101 ^ 0b1001; say $v;'
36

$ p6 'my $v = 0b1101 +^ 0b1001; say $v;'
4

$ p6 'my uint8 $x = infix:<+^>( 0b1000_1010, 0b1010_0110 ); say 
"00", $x.base(2);'

00101100



Bitwise NOT (Ones Complement or flip the bits):
$ p6 'my uint8 $x=0b1010_0110; my uint8 $y = +^$x; my uint8 $z = $y 
+ 1;

  say $x.base(2); say "0", $y.base(2); say "0", $z.base(2);'
10100110  # original
01011001  # one's complement
01011010  # two's complement

   $ p6 'my uint8 $x= 0b1000_1010 +^ 0b1010_0110; say "00", $x.base(2);'
   00101100



Bitwise "IN" or Pattern Test (Does y exist in x):
$ p5 'my $x = 0b1001; my $y = 0b1000; say qw(false true)[($x & $y) 
== $y]'

true

$ p5 'my $x = 0b1001; my $y = 0b0100; say qw(false true)[($x & $y) 
== $y]'

false

$ p6 'my $x=0b1001; my $y=0b0101; my $z=$x +& $y; say so $y == $z;'
False

$ p6 'my $x=0b1001; my $y=0b1001; my $z=$x +& $y; say so $y == $z;'
True


Re: bitwise NOT

2020-01-15 Thread Tom Browder
guys, interesting thread, but it's "complement"

-Tom


Re: bitwise NOT

2020-01-14 Thread Todd Chester via perl6-users
On Tue, Jan 14, 2020 at 7:45 AM Paul Procacci <mailto:pproca...@gmail.com>> wrote:


 >> What is the syntax for a twos complement anyway?

I'm not sure I understand the question.
Two's compliment is +^ ... the routine you've been using.

On Tue, Jan 14, 2020 at 12:33 AM ToddAndMargo via perl6-users
mailto:perl6-users@perl.org>> wrote:

 >> On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users
 >> mailto:perl6-users@perl.org>
<mailto:perl6-users@perl.org <mailto:perl6-users@perl.org>>> wrote:
 >>
 >> Hi All,
 >>
 >> This works,
 >>
 >>  $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say
$d.base(16);'
 >>  5A
 >>
 >> But this does not:
 >>
 >>  $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
 >>  -A6
 >>
 >> 1) who turned it into an negative integer?
 >>
 >> 2) how do I turn it back?
 >>
 >> Many thanks,
 >> -T

On 2020-01-13 21:18, Paul Procacci wrote:
 > If you read the signature for +^, you'll notice it returns an
Int.
 >
 > In your first working example, you're taking a uint8 with
binary value
 > 10100101, zero extending it to 64 bits via +^, applying a two's
 > compliment, and then assigning bits [0:7] to another uint8
which at that
 > point contains the binary value of 01011010 (or hex value 0x5A).
 > In your second example that isn't working, you're taking
uint8 with
 > binary value 10100101, zero extending it to 64 bits via +^,
applying a
 > two's compliment, and then displaying this *Int* (64 bits) as
hex.[1]
 > To turn it back you need to mask off bits [8:63] with: say
((+^$e) +&
 > 0x0FF).base(16);" [2]
 >
 > [1] I'd show you the 64 bit value but it's a bunch of 1's
followed by
 > the value -0xA6.
 > [2] Note, since the type has been promoted to an Int there'
no going
 > back to uint8 without an explicit assignment (afaik)
 >

That explains it.  Thank you.

I used uint8 to keep the ones to a mild torrent!

If I am remembering correctly, 0xA5 going to 0x5A is
a ones compliment.

What is the syntax for a twos complement anyway?





On 2020-01-14 05:14, Gerard ONeill wrote:
A negative number (-A5) is the twos compliment of the positive number.  
A ones compliment is all the bits flipped.  A twos compliment is a ones 
compliment plus one.  So a ones compliment of (A5) is (-A5 - 1), which 
is -A6.


So presumably, the twos compliment operator is (-). And I suppose for 
consistency, +-A5 gives you -A5, which makes +- the twos compliment 
bitwise operator..




It is a pain to keep the variables from being "Coerced to Int",
but this pretty much shows it

$ p6 'my byte $x = 0xA5; say $x.base(16), " original";
  my byte $y = +^$x; say $y.base(16), " ones compliment";
  my byte $z = $x + $y + 1;
  say $z.base(16), "  original + 2s compliment";'

A5 original
5A ones compliment
0  original + 2s compliment


Re: bitwise NOT

2020-01-14 Thread Gerard ONeill
A negative number (-A5) is the twos compliment of the positive number.  A
ones compliment is all the bits flipped.  A twos compliment is a ones
compliment plus one.  So a ones compliment of (A5) is (-A5 - 1), which is
-A6.

So presumably, the twos compliment operator is (-). And I suppose for
consistency, +-A5 gives you -A5, which makes +- the twos compliment bitwise
operator..

On Tue, Jan 14, 2020 at 7:45 AM Paul Procacci  wrote:

> >> What is the syntax for a twos complement anyway?
>
> I'm not sure I understand the question.
> Two's compliment is +^ ... the routine you've been using.
>
> On Tue, Jan 14, 2020 at 12:33 AM ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> >> On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users
>> >> mailto:perl6-users@perl.org>> wrote:
>> >>
>> >> Hi All,
>> >>
>> >> This works,
>> >>
>> >>  $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say
>> $d.base(16);'
>> >>  5A
>> >>
>> >> But this does not:
>> >>
>> >>  $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
>> >>  -A6
>> >>
>> >> 1) who turned it into an negative integer?
>> >>
>> >> 2) how do I turn it back?
>> >>
>> >> Many thanks,
>> >> -T
>>
>> On 2020-01-13 21:18, Paul Procacci wrote:
>> > If you read the signature for +^, you'll notice it returns an Int.
>> >
>> > In your first working example, you're taking a uint8 with binary value
>> > 10100101, zero extending it to 64 bits via +^, applying a two's
>> > compliment, and then assigning bits [0:7] to another uint8 which at
>> that
>> > point contains the binary value of 01011010 (or hex value 0x5A).
>> > In your second example that isn't working, you're taking uint8 with
>> > binary value 10100101, zero extending it to 64 bits via +^, applying a
>> > two's compliment, and then displaying this *Int* (64 bits) as hex.[1]
>> > To turn it back you need to mask off bits [8:63] with: say ((+^$e) +&
>> > 0x0FF).base(16);" [2]
>> >
>> > [1] I'd show you the 64 bit value but it's a bunch of 1's followed by
>> > the value -0xA6.
>> > [2] Note, since the type has been promoted to an Int there' no going
>> > back to uint8 without an explicit assignment (afaik)
>> >
>>
>> That explains it.  Thank you.
>>
>> I used uint8 to keep the ones to a mild torrent!
>>
>> If I am remembering correctly, 0xA5 going to 0x5A is
>> a ones compliment.
>>
>> What is the syntax for a twos complement anyway?
>
>
>>
>
> --
> __
>
> :(){ :|:& };:
>


Re: bitwise NOT

2020-01-14 Thread Paul Procacci
 >> What is the syntax for a twos complement anyway?

I'm not sure I understand the question.
Two's compliment is +^ ... the routine you've been using.

On Tue, Jan 14, 2020 at 12:33 AM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> This works,
> >>
> >>  $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say
> $d.base(16);'
> >>  5A
> >>
> >> But this does not:
> >>
> >>  $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
> >>  -A6
> >>
> >> 1) who turned it into an negative integer?
> >>
> >> 2) how do I turn it back?
> >>
> >> Many thanks,
> >> -T
>
> On 2020-01-13 21:18, Paul Procacci wrote:
> > If you read the signature for +^, you'll notice it returns an Int.
> >
> > In your first working example, you're taking a uint8 with binary value
> > 10100101, zero extending it to 64 bits via +^, applying a two's
> > compliment, and then assigning bits [0:7] to another uint8 which at that
> > point contains the binary value of 01011010 (or hex value 0x5A).
> > In your second example that isn't working, you're taking uint8 with
> > binary value 10100101, zero extending it to 64 bits via +^, applying a
> > two's compliment, and then displaying this *Int* (64 bits) as hex.[1]
> > To turn it back you need to mask off bits [8:63] with: say ((+^$e) +&
> > 0x0FF).base(16);" [2]
> >
> > [1] I'd show you the 64 bit value but it's a bunch of 1's followed by
> > the value -0xA6.
> > [2] Note, since the type has been promoted to an Int there' no going
> > back to uint8 without an explicit assignment (afaik)
> >
>
> That explains it.  Thank you.
>
> I used uint8 to keep the ones to a mild torrent!
>
> If I am remembering correctly, 0xA5 going to 0x5A is
> a ones compliment.
>
> What is the syntax for a twos complement anyway?
>


-- 
__

:(){ :|:& };:


Re: bitwise NOT

2020-01-13 Thread ToddAndMargo via perl6-users
On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


Hi All,

This works,

 $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say $d.base(16);'
 5A

But this does not:

 $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
 -A6

1) who turned it into an negative integer?

2) how do I turn it back?

Many thanks,
-T


On 2020-01-13 21:18, Paul Procacci wrote:

If you read the signature for +^, you'll notice it returns an Int.

In your first working example, you're taking a uint8 with binary value 
10100101, zero extending it to 64 bits via +^, applying a two's 
compliment, and then assigning bits [0:7] to another uint8 which at that 
point contains the binary value of 01011010 (or hex value 0x5A).
In your second example that isn't working, you're taking uint8 with 
binary value 10100101, zero extending it to 64 bits via +^, applying a 
two's compliment, and then displaying this *Int* (64 bits) as hex.[1]
To turn it back you need to mask off bits [8:63] with: say ((+^$e) +& 
0x0FF).base(16);" [2]


[1] I'd show you the 64 bit value but it's a bunch of 1's followed by 
the value -0xA6.
[2] Note, since the type has been promoted to an Int there' no going 
back to uint8 without an explicit assignment (afaik)




That explains it.  Thank you.

I used uint8 to keep the ones to a mild torrent!

If I am remembering correctly, 0xA5 going to 0x5A is
a ones compliment.

What is the syntax for a twos complement anyway?


Re: bitwise NOT

2020-01-13 Thread Paul Procacci
 If you read the signature for +^, you'll notice it returns an Int.

In your first working example, you're taking a uint8 with binary value
10100101, zero extending it to 64 bits via +^, applying a two's compliment,
and then assigning bits [0:7] to another uint8 which at that point contains
the binary value of 01011010 (or hex value 0x5A).
In your second example that isn't working, you're taking uint8 with binary
value 10100101, zero extending it to 64 bits via +^, applying a two's
compliment, and then displaying this *Int* (64 bits) as hex.[1]
To turn it back you need to mask off bits [8:63] with: say ((+^$e) +&
0x0FF).base(16);" [2]

[1] I'd show you the 64 bit value but it's a bunch of 1's followed by the
value -0xA6.
[2] Note, since the type has been promoted to an Int there' no going back
to uint8 without an explicit assignment (afaik)

On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> This works,
>
> $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say $d.base(16);'
> 5A
>
> But this does not:
>
> $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
> -A6
>
> 1) who turned it into an negative integer?
>
> 2) how do I turn it back?
>
> Many thanks,
> -T
>


-- 
__

:(){ :|:& };:


bitwise NOT

2020-01-13 Thread ToddAndMargo via perl6-users

Hi All,

This works,

   $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say $d.base(16);'
   5A

But this does not:

   $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
   -A6

1) who turned it into an negative integer?

2) how do I turn it back?

Many thanks,
-T


Re: bitwise or?

2018-10-06 Thread JJ Merelo
El sáb., 6 oct. 2018 a las 1:17, Timo Paulssen ()
escribió:

> Yes, there is an absolutely tiny mention of it on the page:
>
> Metaoperators
>
> Metaoperators can be parameterized with other operators or subroutines in
> the same way as functions can take functions as parameters. To use a
> subroutine as a parameter, prefix its name with a &. Perl 6 will generate
> the actual combined operator in the background, allowing the mechanism to
> be applied to user defined operators. *To disambiguate chained
> metaoperators, enclose the inner operator in square brackets.* There are
> quite a few metaoperators with different semantics as explained, next.
> If that's even the part you're asking about, that is. And yes, I would
> consider that LTA, making it easier to find, for example by adding an
> example or maybe even a sub-heading, would be really good. Who wants to
> open a ticket? :)
>

Please someone do that. I'm kind of lost among all the long thread, and I
might be wrong about the intention.

JJ


Re: bitwise or?

2018-10-05 Thread Trey Harris
On Fri, Oct 5, 2018 at 8:33 AM Timo Paulssen t...@wakelift.de
 wrote:

It's important to point out that inside metaoperators ("composed
> operators", "combined operators", ...) the [ ] are just for bracketing
> things together — sometimes it's needed to disambiguate, but you can put
> it in anyway to make things clearer.
>
> This has nothing to do with [+] 1, 2, 3, which is a way to spell "add
> these three numbers together".
>
Timo—is this fact formalized in the docs? I can’t find it.
https://docs.perl6.org/routine/= doesn’t mention it, and while
https://docs.perl6.org/language/operators#Assignment_operators gives an
example of using it (with +=, -=, min= and ~=), I can’t find the
metaoperator version’s definition.


> On 05/10/2018 14:26, Brad Gilbert wrote:
> > Note that = is actually a meta operator that can take an infix
> > operator as an argument
> >
> > So
> >
> > $a += 1
> >
> > is really short for
> >
> > $a [+]= 1
> >
> > On Fri, Oct 5, 2018 at 1:02 AM Todd Chester 
> wrote:
> >>
> >>
> >> On 10/4/18 12:13 PM, Brandon Allbery wrote:
> >>> It's fine syntactically, but I think has no effect because it'd be '$v
> =
> >>> $v' after the '+|='. Conceivably some future version of rakudo could
> >>> warn about it having no effect.
> >> That explains it.  Thank you!
>


Re: bitwise paper?

2018-10-05 Thread ToddAndMargo via perl6-users

On 10/2/18 9:15 PM, David Green wrote:

On 2018-10-02 9:57 pm, ToddAndMargo wrote:
Does anyone know of a paper out in web land showing how to do bitwise 
operations?
$ p6 'my $v = 32 & 16; say $v;' 

If you search docs.perl6.org for "bitwise" you will find "+&":

https://docs.perl6.org/language/operators#infix_+;

And sure enough, 'say 32 +& 16' will return '0'.

The other bitwise operators work likewise: almost the same as Perl 5, 
but with a "+" in front (to indicate that they are numeric operators, as 
opposed to plain "&", "|", etc., which are now junctions... and yes, 
there is https://docs.perl6.org/type/Junction for those who dare!).



-David


P.S. Actually, the search returns:
https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator 


...instead of the correct fragment: "#infix_+&"



Hi Brad,

Thank you.  I did find that.  I was hoping to find them all in the
same place, but instead kept searching until I found the ones
I use.  I posted them somewhere else in this thread.

Did I miss a pattern test?

$ p6 'my $x=0b1001; my $y=0b0101; my $z=$x +& $y; say so $y == $z;'
False

$ p6 'my $x=0b1001; my $y=0b1001; my $z=$x +& $y; say so $y == $z;'
True

It is an easy sub to write, if not.

-T


Re: bitwise paper?

2018-10-05 Thread David Green

On 2018-10-02 9:57 pm, ToddAndMargo wrote:
Does anyone know of a paper out in web land showing how to do bitwise 
operations?
$ p6 'my $v = 32 & 16; say $v;' 

If you search docs.perl6.org for "bitwise" you will find "+&":

https://docs.perl6.org/language/operators#infix_+;

And sure enough, 'say 32 +& 16' will return '0'.

The other bitwise operators work likewise: almost the same as Perl 5, 
but with a "+" in front (to indicate that they are numeric operators, as 
opposed to plain "&", "|", etc., which are now junctions... and yes, 
there is https://docs.perl6.org/type/Junction for those who dare!).



-David


P.S. Actually, the search returns:
https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator
...instead of the correct fragment: "#infix_+&"


Re: bitwise or?

2018-10-05 Thread Timo Paulssen
It's important to point out that inside metaoperators ("composed
operators", "combined operators", ...) the [ ] are just for bracketing
things together — sometimes it's needed to disambiguate, but you can put
it in anyway to make things clearer.

This has nothing to do with [+] 1, 2, 3, which is a way to spell "add
these three numbers together".

On 05/10/2018 14:26, Brad Gilbert wrote:
> Note that = is actually a meta operator that can take an infix
> operator as an argument
>
> So
>
> $a += 1
>
> is really short for
>
> $a [+]= 1
>
> On Fri, Oct 5, 2018 at 1:02 AM Todd Chester  wrote:
>>
>>
>> On 10/4/18 12:13 PM, Brandon Allbery wrote:
>>> It's fine syntactically, but I think has no effect because it'd be '$v =
>>> $v' after the '+|='. Conceivably some future version of rakudo could
>>> warn about it having no effect.
>> That explains it.  Thank you!


Re: bitwise or?

2018-10-05 Thread Brad Gilbert
Note that = is actually a meta operator that can take an infix
operator as an argument

So

$a += 1

is really short for

$a [+]= 1

On Fri, Oct 5, 2018 at 1:02 AM Todd Chester  wrote:
>
>
>
> On 10/4/18 12:13 PM, Brandon Allbery wrote:
> > It's fine syntactically, but I think has no effect because it'd be '$v =
> > $v' after the '+|='. Conceivably some future version of rakudo could
> > warn about it having no effect.
>
> That explains it.  Thank you!


Re: bitwise or?

2018-10-05 Thread Todd Chester




On 10/4/18 12:13 PM, Brandon Allbery wrote:
It's fine syntactically, but I think has no effect because it'd be '$v = 
$v' after the '+|='. Conceivably some future version of rakudo could 
warn about it having no effect.


That explains it.  Thank you!


Re: bitwise or?

2018-10-04 Thread Brandon Allbery
It's fine syntactically, but I think has no effect because it'd be '$v =
$v' after the '+|='. Conceivably some future version of rakudo could warn
about it having no effect.

On Thu, Oct 4, 2018 at 3:09 PM ToddAndMargo  wrote:

> On 10/4/18 12:06 PM, ToddAndMargo wrote:
> > On 10/4/18 12:00 PM, JJ Merelo wrote:
> >>
> >>
> >> El jue., 4 oct. 2018 a las 20:58, ToddAndMargo ( >> >) escribió:
> >>
> >> Hi All,
> >>
> >> I am trying to come up with something like +=
> >>
> >>$ p6 'my $v = 32; $v += 2; say $v;'
> >>34
> >>
> >> to replace
> >>
> >>$ p6 'my $v = 0b0010; $v = $v +| 0b0001; say $v;'
> >>48
> >>
> >>
> >> But I obviously have something wrong:
> >>
> >>$ p6 'my $v = 0b0010; $v +| 0b0001; say $v;'
> >>WARNINGS for -e:
> >>Useless use of "+|" in expression "$v +| 0b0001"
> >>in sink context (line 1)
> >>
> >>
> >> You are not assigning the result of the operation to anything.
> >>
> >>  say my $v = 0b0010; $v +|= 0b0001; say $v;   # OUTPUT:
> >> «32␤48␤»
> >>
> >> Cheers
> >>
> >> JJ
> >
> >
> > Hi JJ,
> >
> > I missed an "=".  Thank you!
> >
> > $ p6 'my $v = 0b0010; $v = $v +|= 0b0001; say $v;'
> > 48
> >
> > $ p6 'my $v = 0b0010; $v = $v +|= 0b00010001; say $v;'
> > 49
> >
> > -T
> >
> >
>
>
> OOOPS!!!  I wonder why that did not error out?  had an extra `$v =`
>
>
> Corrected:
>
> $ p6 'my $v = 0b0010; $v +|= 0b00010001; say $v;'
> 49
>
>
> --
> ~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~
>


-- 
brandon s allbery kf8nh
allber...@gmail.com


Re: bitwise or?

2018-10-04 Thread ToddAndMargo

On 10/4/18 12:00 PM, JJ Merelo wrote:



El jue., 4 oct. 2018 a las 20:58, ToddAndMargo (>) escribió:


Hi All,

I am trying to come up with something like +=

       $ p6 'my $v = 32; $v += 2; say $v;'
       34

to replace

       $ p6 'my $v = 0b0010; $v = $v +| 0b0001; say $v;'
       48


But I obviously have something wrong:

       $ p6 'my $v = 0b0010; $v +| 0b0001; say $v;'
       WARNINGS for -e:
       Useless use of "+|" in expression "$v +| 0b0001"
       in sink context (line 1)


You are not assigning the result of the operation to anything.

     say my $v = 0b0010; $v +|= 0b0001; say $v;   # OUTPUT: 
«32␤48␤»


Cheers

JJ



Hi JJ,

I missed an "=".  Thank you!

$ p6 'my $v = 0b0010; $v = $v +|= 0b0001; say $v;'
48

$ p6 'my $v = 0b0010; $v = $v +|= 0b00010001; say $v;'
49

-T


--
~
When we ask for advice, we are usually looking for an accomplice.
   --  Charles Varlet de La Grange
~


Re: bitwise or?

2018-10-04 Thread ToddAndMargo

On 10/4/18 12:06 PM, ToddAndMargo wrote:

On 10/4/18 12:00 PM, JJ Merelo wrote:



El jue., 4 oct. 2018 a las 20:58, ToddAndMargo (>) escribió:


    Hi All,

    I am trying to come up with something like +=

       $ p6 'my $v = 32; $v += 2; say $v;'
       34

    to replace

       $ p6 'my $v = 0b0010; $v = $v +| 0b0001; say $v;'
       48


    But I obviously have something wrong:

       $ p6 'my $v = 0b0010; $v +| 0b0001; say $v;'
       WARNINGS for -e:
       Useless use of "+|" in expression "$v +| 0b0001"
       in sink context (line 1)


You are not assigning the result of the operation to anything.

 say my $v = 0b0010; $v +|= 0b0001; say $v;   # OUTPUT: 
«32␤48␤»


Cheers

JJ



Hi JJ,

I missed an "=".  Thank you!

$ p6 'my $v = 0b0010; $v = $v +|= 0b0001; say $v;'
48

$ p6 'my $v = 0b0010; $v = $v +|= 0b00010001; say $v;'
49

-T





OOOPS!!!  I wonder why that did not error out?  had an extra `$v =`


Corrected:

$ p6 'my $v = 0b0010; $v +|= 0b00010001; say $v;'
49


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: bitwise or?

2018-10-04 Thread ToddAndMargo

On 10/4/18 12:00 PM, Brandon Allbery wrote:
You're not doing anything with '$v +| 0b0001'. Were you looking for 
something like '+|='? (Which I think should work.)


On Thu, Oct 4, 2018 at 2:58 PM ToddAndMargo > wrote:


Hi All,

I am trying to come up with something like +=

       $ p6 'my $v = 32; $v += 2; say $v;'
       34

to replace

       $ p6 'my $v = 0b0010; $v = $v +| 0b0001; say $v;'
       48


But I obviously have something wrong:

       $ p6 'my $v = 0b0010; $v +| 0b0001; say $v;'
       WARNINGS for -e:
       Useless use of "+|" in expression "$v +| 0b0001"
       in sink context (line 1)

       32

Where is my goof?

Many thanks,
-T


Hi Brandon,

Indeed!   Thank you!

$ p6 'my $v = 0b0010; $v +|= 0b00010001; say $v;'
49


-T


--
~
When we ask for advice, we are usually looking for an accomplice.
   --  Charles Varlet de La Grange
~


Re: bitwise or?

2018-10-04 Thread Brandon Allbery
You're not doing anything with '$v +| 0b0001'. Were you looking for
something like '+|='? (Which I think should work.)

On Thu, Oct 4, 2018 at 2:58 PM ToddAndMargo  wrote:

> Hi All,
>
> I am trying to come up with something like +=
>
>   $ p6 'my $v = 32; $v += 2; say $v;'
>   34
>
> to replace
>
>   $ p6 'my $v = 0b0010; $v = $v +| 0b0001; say $v;'
>   48
>
>
> But I obviously have something wrong:
>
>   $ p6 'my $v = 0b0010; $v +| 0b0001; say $v;'
>   WARNINGS for -e:
>   Useless use of "+|" in expression "$v +| 0b0001"
>   in sink context (line 1)
>
>   32
>
> Where is my goof?
>
> Many thanks,
> -T
>


-- 
brandon s allbery kf8nh
allber...@gmail.com


Re: bitwise or?

2018-10-04 Thread JJ Merelo
El jue., 4 oct. 2018 a las 20:58, ToddAndMargo ()
escribió:

> Hi All,
>
> I am trying to come up with something like +=
>
>   $ p6 'my $v = 32; $v += 2; say $v;'
>   34
>
> to replace
>
>   $ p6 'my $v = 0b0010; $v = $v +| 0b0001; say $v;'
>   48
>
>
> But I obviously have something wrong:
>
>   $ p6 'my $v = 0b0010; $v +| 0b0001; say $v;'
>   WARNINGS for -e:
>   Useless use of "+|" in expression "$v +| 0b0001"
>   in sink context (line 1)


You are not assigning the result of the operation to anything.

say my $v = 0b0010; $v +|= 0b0001; say $v;   # OUTPUT: «32␤48␤»

Cheers

JJ


bitwise or?

2018-10-04 Thread ToddAndMargo

Hi All,

I am trying to come up with something like +=

 $ p6 'my $v = 32; $v += 2; say $v;'
 34

to replace

 $ p6 'my $v = 0b0010; $v = $v +| 0b0001; say $v;'
 48


But I obviously have something wrong:

 $ p6 'my $v = 0b0010; $v +| 0b0001; say $v;'
 WARNINGS for -e:
 Useless use of "+|" in expression "$v +| 0b0001"
 in sink context (line 1)

 32

Where is my goof?

Many thanks,
-T


Re: bitwise paper?

2018-10-04 Thread ToddAndMargo

On 10/4/18 10:01 AM, ToddAndMargo wrote:

On 10/3/18 7:16 PM, ToddAndMargo wrote:

Bitwise "IN" (Does y exist in x):

 $ p6 'my $x=0b1001; my $y=0b0101; my $z=$x +& $y; say so $y == $z;'
 False

 $ p6 'my $x=0b1001; my $y=0b1001; my $z=$x +& $y; say so $y == $z;'
 True

 p5 not figured out yet


     $ p5 'my $x = 0b1001; my $y = 0b1000; say qw(false true)[($x & $y) 
== $y]'

     true

     $ p5 'my $x = 0b1001; my $y = 0b0100; say qw(false true)[($x & $y) 
== $y]'

     false


The above is a thing of beauty.  But Perl 6's is even prettier!


Re: bitwise paper?

2018-10-04 Thread ToddAndMargo

On 10/3/18 7:16 PM, ToddAndMargo wrote:

Bitwise "IN" (Does y exist in x):

     $ p6 'my $x=0b1001; my $y=0b0101; my $z=$x +& $y; say so $y == $z;'
     False

     $ p6 'my $x=0b1001; my $y=0b1001; my $z=$x +& $y; say so $y == $z;'
     True

     p5 not figured out yet


$ p5 'my $x = 0b1001; my $y = 0b1000; say qw(false true)[($x & $y) 
== $y]'

true

$ p5 'my $x = 0b1001; my $y = 0b0100; say qw(false true)[($x & $y) 
== $y]'

false


Re: bitwise paper?

2018-10-03 Thread ToddAndMargo

On 10/3/18 7:46 PM, Trey Harris wrote:
Assuming you are suggesting your examples are showing differences 
between the languages, in all your examples of differences between Perl 
6 and Perl 5 below, you are using the wrong operator or you changed one 
of the arguments between the Perl 5 and Perl 6 examples.


I won't go through them each, but for example '> 3' is the greater-than 
operator in Perl 5; 0b0001_0100 (20) is greater than 3, so the answer is 
1 (true). And in your bitwise shift left, you're shifting by 2 in Perl 6 
but by 3 in Perl 5. And so on.




Hi Trey,

Ah poop!  I made another booboo.  Mumble, mumble.

corrected:
$ p5 'my $v = 0b0100 << 3; say $v;'
32

This is my own reference.  I do still maintain a few p5 programs
so I was writing a one size fits all.

Thank you for the catch!

-T


My Keepers is basically a directory by subject:

perl6.String.to.Integer.txt
perl6.string.words.example.txt
perl6.string.zeros.remove.leading.txt
perl6.subroutines.passing.arrays.and.hashes.html
perl6.subroutines.txt
perl6.subs.calling.ones.self.txt
perl6.subs.name.of.sub.txt
perl6.succ.successor.txt
perl6.syntax.check.txt
perl6.syntax.txt

145 of them now.  They are my first line of reference when programming.

For instance: perl6.String.to.Integer.txt  (notice how I start
simple and them more up):



Perl 6: convert String to Integer and Integer to String:


String to Integer:
   $ p6 'my Str $x = "122333"; my Int $y = $x.Int; say $y;'
   122333

   $ p6 'my Int $x; my Str $y = "5"; $x = "$y" + 0; say "$x";'
   5


Integer to String:
   $ p6 'my Int $x = 122333; my Str $y = $x.Str; say $y;'
   122333

   $ p6 'my Str $x; my Int $y = 9; $x = "$y"; say "$x";'
   9

   $ p6 'my Str $x = "1\n22\n333\n"; my Int @y; @y = ( split "\n", $x, 
:skip-empty )>>.Int; for @y -> Int $i {say $i;}'

   1
   22
   333

   $ p6 'my Str $x = "1\n22\n333\n"; my Int @y; for ( split "\n", $x, 
:skip-empty )>>.Int -> $i {say $i;}'

   1
   22
   333


"dd":
   $ p6 'my Str $x = "5"; my Int $y = dd +$x; say $y'
   5
   (Int)

   $ p6 'my Int $y = 7; my Str $x = dd ~$y; say $x'
   "7"
   (Str)


Re: bitwise paper?

2018-10-03 Thread Trey Harris
Todd,

Assuming you are suggesting your examples are showing differences between
the languages, in all your examples of differences between Perl 6 and Perl
5 below, you are using the wrong operator or you changed one of the
arguments between the Perl 5 and Perl 6 examples.

I won't go through them each, but for example '> 3' is the greater-than
operator in Perl 5; 0b0001_0100 (20) is greater than 3, so the answer is 1
(true). And in your bitwise shift left, you're shifting by 2 in Perl 6 but
by 3 in Perl 5. And so on.

If you weren't trying to show differences between the languages but had
some other reason for changing multiple controls at once, never mind me; I
don't know how your "keeper file" works.

(But I should point out that since you at least at some point suggested
it's the sort of stuff you'd like to see in the docs, we don't give Perl 5
comparisons in the part of the docs that don't relate to Perl 5 (just in
the Perl 5 to Perl 6 Guide docs and _very_ rarely in a couple of other
cases that represent bad traps for those who might assume something works
like it does in Perl 5), and when we do give side-by-side examples of two
things, authors have tried to give example that change the minimum required
to show the difference and no more.)


On Wed, Oct 3, 2018 at 22:16 ToddAndMargo  wrote:

> My keeper file so far:
>
> Perl: bitwise operators:
>
> alias p5='perl6 -E'
> alias p6='perl6 -e'
>
>
> Bitwise AND:
>  $ p6 'my $v = 32 +& 16; say $v;'
>  0
>
>  $ p5 'my $v = 32 & 16; say $v;'
>  0
>
>
> Bitwise OR:
>  $ p5 'my $v = 32 | 16; say $v;'
>  48
>
>  $ p6 'my $v = 32 +| 16; say $v;'
>  48
>
>
> Bitwise shift left:
>  $ p6 'my $v = 0b00000100 +< 2; say $v;'
>  16
>
>  $ p5 'my $v = 0b0100 << 3; say $v;'
>  32
>
>
>
> Bitwise shift right:
>  $ p5 'my $v = 0b00010100 > 3; say $v;'
>  1
>
>  $ p6 'my $v = 0b00110100 +> 3; say $v;'
>  6
>
>
> Bitwise XOR:
>  $ p5 'my $v = 0b00101101 ^ 0b1001; say $v;'
>  36
>
>  $ p6 'my $v = 0b1101 +^ 0b1001; say $v;'
>  4
>
>
> Bitwise Compliment (flip the bits):
>  $ p5 'my $x = 0b00101101; my $y= (~$x); my $z= (~$y); say
> "$x\n$y\n$z"; '
>  45
>  18446744073709551570
>  45
>
>  $ p6 'my $x = 0b00101101; my $y= (+^$x); my $z= (+^$y); say
> "$x\n$y\n$z"; '
>  45
>  -46
>  45
>
>
> Bitwise "IN" (Does y exist in x):
>
>  $ p6 'my $x=0b1001; my $y=0b0101; my $z=$x +& $y; say so $y == $z;'
>  False
>
>  $ p6 'my $x=0b1001; my $y=0b1001; my $z=$x +& $y; say so $y == $z;'
>  True
>
>  p5 not figured out yet
>


Re: bitwise paper?

2018-10-03 Thread ToddAndMargo

My keeper file so far:

Perl: bitwise operators:

alias p5='perl6 -E'
alias p6='perl6 -e'


Bitwise AND:
$ p6 'my $v = 32 +& 16; say $v;'
0

$ p5 'my $v = 32 & 16; say $v;'
0


Bitwise OR:
$ p5 'my $v = 32 | 16; say $v;'
48

$ p6 'my $v = 32 +| 16; say $v;'
    48


Bitwise shift left:
$ p6 'my $v = 0b0100 +< 2; say $v;'
16

$ p5 'my $v = 0b0100 << 3; say $v;'
32



Bitwise shift right:
$ p5 'my $v = 0b00010100 > 3; say $v;'
1

$ p6 'my $v = 0b00110100 +> 3; say $v;'
6


Bitwise XOR:
$ p5 'my $v = 0b00101101 ^ 0b1001; say $v;'
36

$ p6 'my $v = 0b1101 +^ 0b1001; say $v;'
4


Bitwise Compliment (flip the bits):
$ p5 'my $x = 0b00101101; my $y= (~$x); my $z= (~$y); say 
"$x\n$y\n$z"; '

45
18446744073709551570
45

$ p6 'my $x = 0b00101101; my $y= (+^$x); my $z= (+^$y); say 
"$x\n$y\n$z"; '

45
-46
45


Bitwise "IN" (Does y exist in x):

$ p6 'my $x=0b1001; my $y=0b0101; my $z=$x +& $y; say so $y == $z;'
False

$ p6 'my $x=0b1001; my $y=0b1001; my $z=$x +& $y; say so $y == $z;'
True

p5 not figured out yet


Re: bitwise paper?

2018-10-03 Thread ToddAndMargo

> I'm looking at
> 
https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator 


> right now and it has entries for every bitwise operator. I suggest you
> hold down the SHIFT key and press reload to clear your browser cache.
>
>
>
> But, now that I know what to look for, I will find the rest, so
> no one offer additional help, unless they just want to.
>
> My goal is to write up a Keeper file for this.  I will post it
> back on this thread when I finish.
>
> -T
>

On 10/3/18 6:00 PM, Trey Harris wrote:


On Wed, Oct 3, 2018 at 20:56 ToddAndMargo <mailto:toddandma...@zoho.com>> wrote:


On 10/3/18 1:50 PM, Trey Harris wrote:
 >
 > On Wed, Oct 3, 2018 at 13:38 ToddAndMargo mailto:toddandma...@zoho.com>
 > <mailto:toddandma...@zoho.com <mailto:toddandma...@zoho.com>>> wrote:
 >
 >      > Go to docs.perl6.org <http://docs.perl6.org>
<http://docs.perl6.org>
 >     <http://docs.perl6.org>. Type "bitwise" into the
 >      > search box. You will see a popup, "Numeric bitwise AND
operator".
 >     Click
 >      > it to be taken to
 >      >
 >

https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator,
 >
 >      > which will tell you the bitwise AND operator in Perl 6 is +&.
 >      >
 >      > Run the same command with +& and you will get the answer 0.
 >      >
 >      > If, on the other hand, you go to docs.perl6.org
<http://docs.perl6.org>
 >     <http://docs.perl6.org> <http://docs.perl6.org>,
 >      > and type "&" into the search box, you will see under "Infix"
 >     (since you
 >      > used the operator between two things, it is Infix, as the docs
 >     say if
 >      > you type "infix" into the search box and click the first
entry under
 >      > "Reference"; I have no idea how you'd divine that such a
thing is
 >     called
 >      > an infix operator aside from common programming parlance,
but if you
 >      > have an idea how that might be expressed it can easily be
added
 >     to the
 >      > index) that the first entry is "&".
 >      >
 >      > Click on this "&" and you are taken to
 > https://docs.perl6.org/routine/;
 >      > which rather clearly says it returns an all Junction.
 >      >
 >      > So I wonder why were you under the impression that the
above "should
 >      > give [you]  "?
 >      >
 >      > Trey
 >
 >
 >     Thank you.
 >
 >     Looks like I am going to have to look them up one at a time.
 >
 >
 > Just because you get to a specific place on a page by typing
something
 > into the search box doesn't mean you can't scroll up and down on the
 > page anyway. You can do the same from +& and see the other
operators, too.
 >

Hi Trey,

That page only give me one page and nothing to scroll up or down on.






Oh, you know what, I had clicked on

https://docs.perl6.org/routine/;

Thank you!


--
~
I am Windows
I am the Blue Screen of Death
No one hears your screams
~


Re: bitwise paper?

2018-10-03 Thread Trey Harris
On Wed, Oct 3, 2018 at 20:56 ToddAndMargo  wrote:

> On 10/3/18 1:50 PM, Trey Harris wrote:
> >
> > On Wed, Oct 3, 2018 at 13:38 ToddAndMargo  > <mailto:toddandma...@zoho.com>> wrote:
> >
> >  > Go to docs.perl6.org <http://docs.perl6.org>
> > <http://docs.perl6.org>. Type "bitwise" into the
> >  > search box. You will see a popup, "Numeric bitwise AND operator".
> > Click
> >  > it to be taken to
> >  >
> >
> https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator
> ,
> >
> >  > which will tell you the bitwise AND operator in Perl 6 is +&.
> >  >
> >  > Run the same command with +& and you will get the answer 0.
> >  >
> >  > If, on the other hand, you go to docs.perl6.org
> > <http://docs.perl6.org> <http://docs.perl6.org>,
> >  > and type "&" into the search box, you will see under "Infix"
> > (since you
> >  > used the operator between two things, it is Infix, as the docs
> > say if
> >  > you type "infix" into the search box and click the first entry
> under
> >  > "Reference"; I have no idea how you'd divine that such a thing is
> > called
> >  > an infix operator aside from common programming parlance, but if
> you
> >  > have an idea how that might be expressed it can easily be added
> > to the
> >  > index) that the first entry is "&".
> >  >
> >  > Click on this "&" and you are taken to
> > https://docs.perl6.org/routine/;
> >  > which rather clearly says it returns an all Junction.
> >  >
> >  > So I wonder why were you under the impression that the above
> "should
> >  > give [you]  "?
> >  >
> >  > Trey
> >
> >
> > Thank you.
> >
> > Looks like I am going to have to look them up one at a time.
> >
> >
> > Just because you get to a specific place on a page by typing something
> > into the search box doesn't mean you can't scroll up and down on the
> > page anyway. You can do the same from +& and see the other operators,
> too.
> >
>
> Hi Trey,
>
> That page only give me one page and nothing to scroll up or down on.



I'm looking at
https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator
right now and it has entries for every bitwise operator. I suggest you hold
down the SHIFT key and press reload to clear your browser cache.


>
> But, now that I know what to look for, I will find the rest, so
> no one offer additional help, unless they just want to.
>
> My goal is to write up a Keeper file for this.  I will post it
> back on this thread when I finish.
>
> -T
>


Re: bitwise paper?

2018-10-03 Thread ToddAndMargo

On 10/3/18 1:50 PM, Trey Harris wrote:


On Wed, Oct 3, 2018 at 13:38 ToddAndMargo <mailto:toddandma...@zoho.com>> wrote:


 > Go to docs.perl6.org <http://docs.perl6.org>
<http://docs.perl6.org>. Type "bitwise" into the
 > search box. You will see a popup, "Numeric bitwise AND operator".
Click
 > it to be taken to
 >

https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator,

 > which will tell you the bitwise AND operator in Perl 6 is +&.
 >
 > Run the same command with +& and you will get the answer 0.
 >
 > If, on the other hand, you go to docs.perl6.org
<http://docs.perl6.org> <http://docs.perl6.org>,
 > and type "&" into the search box, you will see under "Infix"
(since you
 > used the operator between two things, it is Infix, as the docs
say if
 > you type "infix" into the search box and click the first entry under
 > "Reference"; I have no idea how you'd divine that such a thing is
called
 > an infix operator aside from common programming parlance, but if you
 > have an idea how that might be expressed it can easily be added
to the
 > index) that the first entry is "&".
 >
 > Click on this "&" and you are taken to
https://docs.perl6.org/routine/;
 > which rather clearly says it returns an all Junction.
 >
 > So I wonder why were you under the impression that the above "should
 > give [you]  "?
 >
 > Trey


Thank you.

Looks like I am going to have to look them up one at a time.


Just because you get to a specific place on a page by typing something 
into the search box doesn't mean you can't scroll up and down on the 
page anyway. You can do the same from +& and see the other operators, too.




Hi Trey,

That page only give me one page and nothing to scroll up or down on.

But, now that I know what to look for, I will find the rest, so
no one offer additional help, unless they just want to.

My goal is to write up a Keeper file for this.  I will post it
back on this thread when I finish.

-T


Re: bitwise paper?

2018-10-03 Thread Trey Harris
On Wed, Oct 3, 2018 at 13:38 ToddAndMargo  wrote:

> > Go to docs.perl6.org <http://docs.perl6.org>. Type "bitwise" into the
> > search box. You will see a popup, "Numeric bitwise AND operator". Click
> > it to be taken to
> >
> https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator,
>
> > which will tell you the bitwise AND operator in Perl 6 is +&.
> >
> > Run the same command with +& and you will get the answer 0.
> >
> > If, on the other hand, you go to docs.perl6.org <http://docs.perl6.org>,
>
> > and type "&" into the search box, you will see under "Infix" (since you
> > used the operator between two things, it is Infix, as the docs say if
> > you type "infix" into the search box and click the first entry under
> > "Reference"; I have no idea how you'd divine that such a thing is called
> > an infix operator aside from common programming parlance, but if you
> > have an idea how that might be expressed it can easily be added to the
> > index) that the first entry is "&".
> >
> > Click on this "&" and you are taken to https://docs.perl6.org/routine/;
> > which rather clearly says it returns an all Junction.
> >
> > So I wonder why were you under the impression that the above "should
> > give [you]  "?
> >
> > Trey
>
>
> Thank you.
>
> Looks like I am going to have to look them up one at a time.


Just because you get to a specific place on a page by typing something into
the search box doesn't mean you can't scroll up and down on the page
anyway. You can do the same from +& and see the other operators, too.


Re: bitwise paper?

2018-10-03 Thread ToddAndMargo

On 10/2/18 9:46 PM, Trey Harris wrote:


On Tue, Oct 2, 2018 at 23:57 ToddAndMargo <mailto:toddandma...@zoho.com>> wrote:


Hi All,

Does anyone know of a paper out in web land showing how to
do bitwise operations?  DuckDuckGo give me tons of hits
for Perl 5.

Trying to AND 0010  with 0001 

$ p6 'my $v = 32 & 16; say $v;'
all(32, 16)

should give me  .


"Should give you"? Why do you say that?


If P6 was asked correctly to do a bitwise AND,
it would give that result.  Obviously, it is
not being asked correctly.



Go to docs.perl6.org <http://docs.perl6.org>. Type "bitwise" into the 
search box. You will see a popup, "Numeric bitwise AND operator". Click 
it to be taken to
https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator, 
which will tell you the bitwise AND operator in Perl 6 is +&.


Run the same command with +& and you will get the answer 0.

If, on the other hand, you go to docs.perl6.org <http://docs.perl6.org>, 
and type "&" into the search box, you will see under "Infix" (since you 
used the operator between two things, it is Infix, as the docs say if 
you type "infix" into the search box and click the first entry under 
"Reference"; I have no idea how you'd divine that such a thing is called 
an infix operator aside from common programming parlance, but if you 
have an idea how that might be expressed it can easily be added to the 
index) that the first entry is "&".


Click on this "&" and you are taken to https://docs.perl6.org/routine/; 
which rather clearly says it returns an all Junction.


So I wonder why were you under the impression that the above "should 
give [you]  "?


Trey



Thank you.

Looks like I am going to have to look them up one at a time.
The paper I had from Perl 5 had them all in a table.  AND, OR, NOR,
NAND, XOR, IN, shift left, shift right, etc..

-T


Re: bitwise paper?

2018-10-03 Thread ToddAndMargo

On 10/2/18 10:16 PM, David Green wrote:

On 2018-10-02 9:57 pm, ToddAndMargo wrote:
Does anyone know of a paper out in web land showing how to do bitwise 
operations?

Trying to AND 0010  with 0001 
$ p6 'my $v = 32 & 16; say $v;' 

If you search docs.perl6.org for "bitwise" you will find "+&":

https://docs.perl6.org/language/operators#infix_+;

And sure enough, 'say 32 +& 16' will return '0'.

The other bitwise operators work likewise: almost the same as Perl 5, 
but with a "+" in front (to indicate that they are numeric operators, as 
opposed to plain "&", "|", etc., which are now junctions... and yes, 
there is https://docs.perl6.org/type/Junction for those who dare!).



-David


P.S. Actually, the search returns:
https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator 

...instead of the correct fragment: "#infix_+&" -- is that generated 
automatically?


Thank you.

Looks like I am going to have to look them up one at a time.
The paper I had from Perl 5 had hem in a table.  AND, OR, NOR,
NAND, XOR, IN, shift left, shift right, etc..

-T


Re: bitwise paper?

2018-10-02 Thread David Green

On 2018-10-02 9:57 pm, ToddAndMargo wrote:
Does anyone know of a paper out in web land showing how to do bitwise 
operations?

Trying to AND 0010  with 0001 
$ p6 'my $v = 32 & 16; say $v;' 

If you search docs.perl6.org for "bitwise" you will find "+&":

https://docs.perl6.org/language/operators#infix_+;

And sure enough, 'say 32 +& 16' will return '0'.

The other bitwise operators work likewise: almost the same as Perl 5, 
but with a "+" in front (to indicate that they are numeric operators, as 
opposed to plain "&", "|", etc., which are now junctions... and yes, 
there is https://docs.perl6.org/type/Junction for those who dare!).



-David


P.S. Actually, the search returns:
https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator
...instead of the correct fragment: "#infix_+&" -- is that generated 
automatically?


Re: bitwise paper?

2018-10-02 Thread Trey Harris
On Tue, Oct 2, 2018 at 23:57 ToddAndMargo  wrote:

> Hi All,
>
> Does anyone know of a paper out in web land showing how to
> do bitwise operations?  DuckDuckGo give me tons of hits
> for Perl 5.
>
> Trying to AND 0010  with 0001 
>
> $ p6 'my $v = 32 & 16; say $v;'
> all(32, 16)
>
> should give me  .


"Should give you"? Why do you say that?

Go to docs.perl6.org. Type "bitwise" into the search box. You will see a
popup, "Numeric bitwise AND operator". Click it to be taken to
https://docs.perl6.org/language/operators#index-entry-Numeric_bitwise_AND_operator,
which will tell you the bitwise AND operator in Perl 6 is +&.

Run the same command with +& and you will get the answer 0.

If, on the other hand, you go to docs.perl6.org, and type "&" into the
search box, you will see under "Infix" (since you used the operator between
two things, it is Infix, as the docs say if you type "infix" into the
search box and click the first entry under "Reference"; I have no idea how
you'd divine that such a thing is called an infix operator aside from
common programming parlance, but if you have an idea how that might be
expressed it can easily be added to the index) that the first entry is "&".

Click on this "&" and you are taken to https://docs.perl6.org/routine/;
which rather clearly says it returns an all Junction.

So I wonder why were you under the impression that the above "should give
[you]  "?

Trey


bitwise paper?

2018-10-02 Thread ToddAndMargo

Hi All,

Does anyone know of a paper out in web land showing how to
do bitwise operations?  DuckDuckGo give me tons of hits
for Perl 5.

Trying to AND 0010  with 0001 

$ p6 'my $v = 32 & 16; say $v;'
all(32, 16)

should give me  .


I have a nice paper on Perl 5.  I don't think they the same?

$ perl -E 'my $v = 32 & 16; say $v;'
0

$ perl -E 'my $v = 32 | 16; say $v;'
48



Many thanks,
-T