My keeper on hashes

Hi All,

My favorite variable is the associative array (hash).  I finally updated 
my keeper file on them.

If anyone is interested, here goes!

-T


Perl 6 Hashes (associative arrays):

References:
    https://docs.perl6.org/language/subscripts#Basics
    https://docs.perl6.org/type/Hash#:exists


A hash "associates" a Name, called a "key" to a Value, called a "value"

    You assign them as follows;

       # use whatever is easiest on the eyes
       my %h =   a => "A", b => "B";      or
       my %h = ( a => "A", b => "B" );    or
       my %h = [ a => "A", b => "B" ];
       {a => A, b => B}

       say %h.keys
       (b a)

       say %h.values
       (B A)

    You read them as follows:
       $v = %h<b>
       B

       When the key is a variable, your read them as follows
          $k = "a"
          $v = %h{$k}
          A


    Looping through a hash:
    Note: hashes DO NOT loop in the order that they were entered into 
the hash

        for @x.kv -> $key, $value {do something};

        For example:

           my %h = a => "x", b=>"r", c=>"z";
           for %h.kv ->  $key, $value {say "key = $key  value = $value"; }
           key = c  value = z
           key = a  value = x
           key = b  value = r

    Array's of hashes:
        my @a;
        my %h1; my %h2;

        %h1 = a => 0, b => 1, c => 2;
        %h2 = a => 9, b => 8, c => 7;

        push @a, {%h1};
        push @a, {%h2};

        say @a;
        [{a => 0, b => 1, c => 2} {a => 0, b => 1, c => 2}]

        for @a.kv -> $i, $h { say "$i\n" ~ "$h\n"; };
        # Note: the ~ is to make it easier to read
        #       even though $h is address as $ it is a hash
            0
            a	0
            b	1
            c	2

            1
            a	9
            b	8
            c	7


     Checking for the presence of a key/value:
        my %h = a => "x", b=>"r", c=>"z";
        if %h<c> { say "exists"; } else { say "DOES NOT exist"; }
        DOES NOT exist

        if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
        exists


    Deleting a key/value pair:
    Note: "delete" is called an "adverb" in this context
        my %h = a => "x", b=>"r", c=>"z";
        %h<b>:delete; say %h
        {a => x, c => z}


    Display a key/value pair  (:p adverb):
        my %h = a => "x", b=>"r", c=>"z";
        say %h<a>:p;
        a => x
        say %h<a b>:p;   # note: no comma between the a and the b
        (a => x b => r)


    Return the key and value with the :k and :bv adverbs:
        my %h = a => 1, b => 2;
        say %h<a>:k;
        a

        say %h<a b>:k;
       (a b)

       say %h<a b>:v;
       (1 2)

       Empty <> return everything:
          say %h<>:v;
          (2 1)

          say %h<>:k;
          (b a)
0
perl6
12/6/2019 10:39:20 AM
perl.perl6.users 1384 articles. 0 followers. Follow

16 Replies
78 Views

Similar Articles

[PageSpeed] 31

--00000000000057316605990d2772
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

El vie., 6 dic. 2019 a las 11:46, ToddAndMargo via perl6-users (<
perl6-users@perl.org>) escribi=C3=B3:

> Hi All,
>
> My favorite variable is the associative array (hash).  I finally updated
> my keeper file on them.
>
> If anyone is interested, here goes!
>
> -T
>
>
> Perl 6 Hashes (associative arrays):
>
> References:
>     https://docs.perl6.org/language/subscripts#Basics
>     https://docs.perl6.org/type/Hash#:exists
>
>
>
Please use the new URLs, those are deprecated, are no longer updated, and
might stop working without prior notice:

https://docs.raku.org/language/subscripts#Basics
https://docs.raku.org/type/Hash#:exists

Cheers

JJ

--00000000000057316605990d2772
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">El vie., 6 dic. 2019 a las 11:46, Tod=
dAndMargo via perl6-users (&lt;<a href=3D"mailto:perl6-users@perl.org">perl=
6-users@perl.org</a>&gt;) escribi=C3=B3:<br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,20=
4,204);padding-left:1ex">Hi All,<br>
<br>
My favorite variable is the associative array (hash).=C2=A0 I finally updat=
ed <br>
my keeper file on them.<br>
<br>
If anyone is interested, here goes!<br>
<br>
-T<br>
<br>
<br>
Perl 6 Hashes (associative arrays):<br>
<br>
References:<br>
=C2=A0 =C2=A0 <a href=3D"https://docs.perl6.org/language/subscripts#Basics"=
 rel=3D"noreferrer" target=3D"_blank">https://docs.perl6.org/language/subsc=
ripts#Basics</a><br>
=C2=A0 =C2=A0 <a href=3D"https://docs.perl6.org/type/Hash#:exists" rel=3D"n=
oreferrer" target=3D"_blank">https://docs.perl6.org/type/Hash#:exists</a><b=
r>
<br>
<br></blockquote><div><br></div><div>Please use the new URLs, those are dep=
recated, are no longer updated, and might stop working without prior notice=
:</div></div><div><br></div><div><a href=3D"https://docs.raku.org/language/=
subscripts#Basics">https://docs.raku.org/language/subscripts#Basics</a></di=
v><div><a href=3D"https://docs.raku.org/type/Hash#:exists">https://docs.rak=
u.org/type/Hash#:exists</a></div><div><br></div><div>Cheers</div><div><br><=
/div><div>JJ<br></div></div>

--00000000000057316605990d2772--
0
jjmerelo
12/6/2019 6:24:05 PM
On 2019-12-06 10:24, JJ Merelo wrote:

> Please use the new URLs, those are deprecated, are no longer updated, 
> and might stop working without prior notice:
> 
> https://docs.raku.org/language/subscripts#Basics
> https://docs.raku.org/type/Hash#:exists
> 
> Cheers
> 
> JJ

Hi JJ,

Good catch.  Thank you!

I have refined the keeper to include your modifications
and have added how to access values inside and array
and how to add key/pairs to an existing hash.  I also
correct the :bv adverbs typo

-T


Perl 6 Hashes (associative arrays):

References:
     https://docs.raku.org/language/subscripts#Basics
     https://docs.raku.org/type/Hash#___top
     https://docs.raku.org/type/Hash#:exists
     https://docs.raku.org/type/Hash#method_append



A hash "associates" a Name, called a "key" to a Value, called a "value"

    You assign them as follows:

       # use whatever is easiest on the eyes
       my %h =   a => "A", b => "B";      or
       my %h = ( a => "A", b => "B" );    or
       my %h = [ a => "A", b => "B" ];
       {a => A, b => B}

       say %h.keys
       (b a)

       say %h.values
       (B A)

    You read them as follows:
       $v = %h<b>
       B

       When the key is a variable, your read them as follows
          $k = "a"
          $v = %h{$k}
          A

    To add or delete and element, see the sections below labeled
          Adding a key/value pair:
          Deleting a key/value pair:


    Looping through a hash:
    Note: hashes DO NOT loop in the order that they were entered into 
the hash

        for @x.kv -> $key, $value {do something};

        For example:

           my %h = a => "x", b=>"r", c=>"z";
           for %h.kv ->  $key, $value {say "key = $key  value = $value"; }
           key = c  value = z
           key = a  value = x
           key = b  value = r

    Array's of hashes:
        To access values inside and array of hashes:
              my @a; my %h = a=>"A", b=>"B"; push @a, %h;
              Access:
                  $x = @a[0]{"a"}    # Note: you need the quotes

              modify:
                  @a[0]{"b"} = "BB"

        How to use arrays of hashes:
           my @a;
           my %h1; my %h2;

           %h1 = a => 0, b => 1, c => 2;
           %h2 = a => 9, b => 8, c => 7;

           push @a, {%h1};
          push @a, {%h2};

           say @a;
           [{a => 0, b => 1, c => 2} {a => 0, b => 1, c => 2}]

           for @a.kv -> $i, $h { say "$i\n" ~ "$h\n"; };
           # Note: the ~ is to make it easier to read
           #       even though $h is address as $ it is a hash
               0
               a 0
               b	1
               c	2

               1
               a	9
               b	8
               c	7


     Checking for the presence of a key/value:
        my %h = a => "x", b=>"r", c=>"z";
        if %h<c> { say "exists"; } else { say "DOES NOT exist"; }
        DOES NOT exist

        if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
        exists


    Adding a key/value pair:
        my %h = a => "x", b=>"r", c=>"z";
        %h.append( 'd',  "D" )               # note: you need the ''
        {a => x, b => r, c => z, d => D}


    Deleting a key/value pair:
    Note: "delete" is called an "adverb" in this context
        my %h = a => "x", b=>"r", c=>"z";
        %h<b>:delete; say %h
        {a => x, c => z}


    Display a key/value pair  (:p adverb):
        my %h = a => "x", b=>"r", c=>"z";
        say %h<a>:p;
        a => x
        say %h<a b>:p;   # note: no comma between the a and the b
        (a => x b => r)


    Return the key and value with the :k and :v adverbs:
        my %h = a => 1, b => 2;
        say %h<a>:k;
        a

        say %h<a b>:k;
       (a b)

       say %h<a b>:v;
       (1 2)

       Empty <> return everything:
          say %h<>:v;
          (2 1)

          say %h<>:k;
          (b a)
0
perl6
12/7/2019 12:15:34 AM
On 2019-12-06 16:15, ToddAndMargo via perl6-users wrote:
>  =C2=A0=C2=A0=C2=A0=C2=A0Checking=C2=A0for=C2=A0the=C2=A0presence=C2=A0=
of=C2=A0a=C2=A0key/value:
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0my=C2=A0%h=C2=A0=3D=C2=A0a=C2=
=A0=3D>=C2=A0"x",=C2=A0b=3D>"r",=C2=A0c=3D>"z";
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if=C2=A0%h<c>=C2=A0{=C2=A0sa=
y=C2=A0"exists";=C2=A0}=C2=A0else=C2=A0{=C2=A0say=C2=A0"DOES=C2=A0NOT=C2=A0=
exist";=C2=A0}
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0DOES=C2=A0NOT=C2=A0exist
>=20
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if=C2=A0%h<b>=C2=A0{=C2=A0sa=
y=C2=A0"exists";=C2=A0}=C2=A0else=C2=A0{=C2=A0say=C2=A0"DOES=C2=A0NOT=C2=A0=
exist";=C2=A0}
>  =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0exists


Oooops!  Mark caught a typo. `%h<c>` should have been ` %h<d>`

Corrected code:

     Checking for the presence of a key/value:
        my %h =3D a =3D> "x", b=3D>"r", c=3D>"z";
        if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
        DOES NOT exist

        if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
        exists


Thank you Mark!
-T
0
perl6
12/8/2019 2:16:41 AM
On 2019-12-07 18:30, Mark Senn wrote:
>> Corrected section
>>
>>         my %h = a => "x", b=>"r", c=>"z";
>>         if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
>>         DOES NOT exist
>>
>>         if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
>>         exists
> 
> Hi.
> 
> The following code prints DOES NOT exist twice.
> 
> my %h = a => "x", b=>0, c=>"z";
> if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
> 
> if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
> 
> 
> I changed the b=>"r" to b=>0.  I think it is evaluating
> the b element as a boolean---I think the exists adverb
> needs to be used to check for existence.
> 
> -m
> 

Hi Mark,

Oh bugger!


This is what I get:

$ perl6
To exit type 'exit' or '^D'
 > my %h = a => "x", b=>"r", c=>"z";
{a => x, b => r, c => z}

 > if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
DOES NOT exist

 > if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
exists


Would someone else please run my code and see if
they can reproduce Mark's error?

Many thanks,
-T
0
perl6
12/8/2019 5:34:26 AM
On Sat, Dec 7, 2019 at 9:36 PM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> On 2019-12-07 18:30, Mark Senn wrote:
> >> Corrected section
> >>
> >>         my %h = a => "x", b=>"r", c=>"z";
> >>         if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
> >>         DOES NOT exist
> >>
> >>         if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
> >>         exists
> >
> > Hi.
> >
> > The following code prints DOES NOT exist twice.
> >
> > my %h = a => "x", b=>0, c=>"z";
> > if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
> >
> > if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
> >
> >
> > I changed the b=>"r" to b=>0.  I think it is evaluating
> > the b element as a boolean---I think the exists adverb
> > needs to be used to check for existence.
> >
> > -m
> >
>
> Hi Mark,
>
> Oh bugger!
>
>
> This is what I get:
>
> $ perl6
> To exit type 'exit' or '^D'
>  > my %h = a => "x", b=>"r", c=>"z";
> {a => x, b => r, c => z}
>
>  > if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
> DOES NOT exist
>
>  > if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
> exists
>
>
> Would someone else please run my code and see if
> they can reproduce Mark's error?
>
> Many thanks,
> -T

Mark is correct. Changing values to 1 or 0 results in if/else
evaluating as a True/False:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my %i = a => 1, b=> 0, c=> 1;
{a => 1, b => 0, c => 1}
> if %i<a> { say "exists"; } else { say "DOES NOT exist"; }
exists
> if %i<b> { say "exists"; } else { say "DOES NOT exist"; }
DOES NOT exist
> if %i<d> { say "exists"; } else { say "DOES NOT exist"; }
DOES NOT exist
>
> $*VM
moar (2019.07.1)
>

HTH, Bill.
0
perl6
12/8/2019 6:43:49 AM
On 2019-12-07 22:43, William Michels via perl6-users wrote:
> On Sat, Dec 7, 2019 at 9:36 PM ToddAndMargo via perl6-users
> <perl6-users@perl.org> wrote:
>>
>> On 2019-12-07 18:30, Mark Senn wrote:
>>>> Corrected section
>>>>
>>>>          my %h = a => "x", b=>"r", c=>"z";
>>>>          if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
>>>>          DOES NOT exist
>>>>
>>>>          if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
>>>>          exists
>>>
>>> Hi.
>>>
>>> The following code prints DOES NOT exist twice.
>>>
>>> my %h = a => "x", b=>0, c=>"z";
>>> if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
>>>
>>> if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
>>>
>>>
>>> I changed the b=>"r" to b=>0.  I think it is evaluating
>>> the b element as a boolean---I think the exists adverb
>>> needs to be used to check for existence.
>>>
>>> -m
>>>
>>
>> Hi Mark,
>>
>> Oh bugger!
>>
>>
>> This is what I get:
>>
>> $ perl6
>> To exit type 'exit' or '^D'
>>   > my %h = a => "x", b=>"r", c=>"z";
>> {a => x, b => r, c => z}
>>
>>   > if %h<d> { say "exists"; } else { say "DOES NOT exist"; }
>> DOES NOT exist
>>
>>   > if %h<b> { say "exists"; } else { say "DOES NOT exist"; }
>> exists
>>
>>
>> Would someone else please run my code and see if
>> they can reproduce Mark's error?
>>
>> Many thanks,
>> -T
> 
> Mark is correct. Changing values to 1 or 0 results in if/else
> evaluating as a True/False:
> 
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
>> my %i = a => 1, b=> 0, c=> 1;
> {a => 1, b => 0, c => 1}
>> if %i<a> { say "exists"; } else { say "DOES NOT exist"; }
> exists
>> if %i<b> { say "exists"; } else { say "DOES NOT exist"; }
> DOES NOT exist
>> if %i<d> { say "exists"; } else { say "DOES NOT exist"; }
> DOES NOT exist
>>
>> $*VM
> moar (2019.07.1)
>>
> 
> HTH, Bill.
> 

Thank you.

Back to the drawing board.  I think there is an adverb for this.
0
perl6
12/8/2019 9:25:45 AM
On 2019-12-06 02:39, ToddAndMargo via perl6-users wrote:
> Hi All,
>=20
> My favorite variable is the associative array (hash).=C2=A0 I finally u=
pdated=20
> my keeper file on them.
>=20
> If anyone is interested, here goes!
>=20
> -T
>=20

Hi All,

Okay, here it is again with the booboo Mark pointed
to me corrected.

Please feel free to criticize anything you find wrong,
there may be other booboo too.

-T


12/08/2019:

Perl 6 Hashes (associative arrays):


References:
     https://docs.raku.org/language/subscripts#Basics
     https://docs.raku.org/type/Hash#___top
     https://docs.raku.org/type/Hash#:exists
     https://docs.raku.org/type/Hash#method_append



A hash "associates" a Name, called a "key" to a Value, called a "value"

    You assign them as follows:

       # use whatever is easiest on the eyes
       my %h =3D   a =3D> "A", b =3D> "B";      or
       my %h =3D ( a =3D> "A", b =3D> "B" );    or
       my %h =3D [ a =3D> "A", b =3D> "B" ];
       {a =3D> A, b =3D> B}

       say %h.keys
       (b a)

       say %h.values
       (B A)

    You read them as follows:
       $v =3D %h<b>
       B

       When the key is a variable, your read them as follows
          $k =3D "a"
          $v =3D %h{$k}
          A

    To add or delete and element, see the sections below labeled
          Adding a key/value pair:
          Deleting a key/value pair:


    Looping through a hash:
    Note: hashes DO NOT loop in the order that they were entered into=20
the hash

        for @x.kv -> $key, $value {do something};

        For example:

           my %h =3D a =3D> "x", b=3D>"r", c=3D>"z";
           for %h.kv ->  $key, $value {say "key =3D $key  value =3D $valu=
e"; }
           key =3D c  value =3D z
           key =3D a  value =3D x
           key =3D b  value =3D r

    Array's of hashes:
        To access values inside and array of hashes:
              my @a; my %h =3D a=3D>"A", b=3D>"B"; push @a, %h;
              Access:
                  $x =3D @a[0]{"a"}    # Note: you need the quotes

              modify:
                  @a[0]{"b"} =3D "BB"

        How to use arrays of hashes:
           my @a;
           my %h1; my %h2;

           %h1 =3D a =3D> 0, b =3D> 1, c =3D> 2;
           %h2 =3D a =3D> 9, b =3D> 8, c =3D> 7;

           push @a, {%h1};
          push @a, {%h2};

           say @a;
           [{a =3D> 0, b =3D> 1, c =3D> 2} {a =3D> 0, b =3D> 1, c =3D> 2}=
]

           for @a.kv -> $i, $h { say "$i\n" ~ "$h\n"; };
           # Note: the ~ is to make it easier to read
           #       even though $h is address as $ it is a hash
               0
               a 0
               b	1
               c	2

               1
               a	9
               b	8
               c	7


     Checking for the presence of a key/value:

       Warning: a Gotcha:
            if using the "if" statement to check for the existence
            of a key, it will return false if it does not find the key,
            but it will also return false if it finds the key and its
            value is a numerical zero, which "if" interprets as
            a Boolean false.

        Note: "exists" is called an "adverb" in this context
           my %h =3D a =3D> "x", b=3D>0, c=3D>"z";

           if %h<d>:exists { say "exists"; } else { say "DOES NOT exist";=
 }
           DOES NOT exist

           if %h<b>:exists { say "exists"; } else { say "DOES NOT exist";=
 }
           exists



    Adding a key/value pair:
        my %h =3D a =3D> "x", b=3D>"r", c=3D>"z";
        %h.append( 'd',  "D" )               # note: you need the ''
        {a =3D> x, b =3D> r, c =3D> z, d =3D> D}


    Deleting a key/value pair:
    Note: "delete" is called an "adverb" in this context
        my %h =3D a =3D> "x", b=3D>"r", c=3D>"z";
        %h<b>:delete; say %h
        {a =3D> x, c =3D> z}


    Display a key/value pair  (:p adverb):
        my %h =3D a =3D> "x", b=3D>"r", c=3D>"z";
        say %h<a>:p;
        a =3D> x
        say %h<a b>:p;   # note: no comma between the a and the b
        (a =3D> x b =3D> r)


    Return the key and value with the :k and :v adverbs:
        my %h =3D a =3D> 1, b =3D> 2;
        say %h<a>:k;
        a

        say %h<a b>:k;
       (a b)

       say %h<a b>:v;
       (1 2)

       Empty <> return everything:
          say %h<>:v;
          (2 1)

          say %h<>:k;
          (b a)
0
perl6
12/8/2019 10:31:48 AM
A recent addition to my hashes keeper:


    Confining hashes:
    Note: as of 2020-01-15, confining only works with Str.
          And you must confine the entire hash, not each member

       my Str %h = A => "a"
       {A => a}

       my int %h = A => 123
       native value types for hashes not yet implemented. Sorry.
0
perl6
1/16/2020 2:00:38 AM
--0000000000001018dc059c38923b
Content-Type: text/plain; charset="UTF-8"

Capital I in Int, to not use native type

> my Int %h = A => 123

{A => 123}

-y


On Wed, Jan 15, 2020 at 6:00 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> A recent addition to my hashes keeper:
>
>
>     Confining hashes:
>     Note: as of 2020-01-15, confining only works with Str.
>           And you must confine the entire hash, not each member
>
>        my Str %h = A => "a"
>        {A => a}
>
>        my int %h = A => 123
>        native value types for hashes not yet implemented. Sorry.
>

--0000000000001018dc059c38923b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">Capital I in Int, to not use native type<=
div><p style=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:n=
ormal;font-family:Menlo;color:rgb(0,0,0)"><span style=3D"font-variant-ligat=
ures:no-common-ligatures">&gt; my Int %h =3D A =3D&gt; 123</span></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:norma=
l;font-family:Menlo;color:rgb(0,0,0)"><span style=3D"font-variant-ligatures=
:no-common-ligatures">{A =3D&gt; 123}</span></p><div><br clear=3D"all"><div=
><div dir=3D"ltr" class=3D"gmail_signature">-y<br></div></div><br></div></d=
iv></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gma=
il_attr">On Wed, Jan 15, 2020 at 6:00 PM ToddAndMargo via perl6-users &lt;<=
a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<=
br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,2=
04,204);padding-left:1ex">A recent addition to my hashes keeper:<br>
<br>
<br>
=C2=A0 =C2=A0 Confining hashes:<br>
=C2=A0 =C2=A0 Note: as of 2020-01-15, confining only works with Str.<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 And you must confine the entire hash, no=
t each member<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0my Str %h =3D A =3D&gt; &quot;a&quot;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0{A =3D&gt; a}<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0my int %h =3D A =3D&gt; 123<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0native value types for hashes not yet implemente=
d. Sorry.<br>
</blockquote></div>

--0000000000001018dc059c38923b--
0
not
1/16/2020 2:27:34 AM
>> On Wed, Jan 15, 2020 at 6:00 PM ToddAndMargo via perl6-users 
>> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
>> 
>>     A recent addition to my hashes keeper:
>> 
>> 
>>          Confining hashes:
>>          Note: as of 2020-01-15, confining only works with Str.
>>                And you must confine the entire hash, not each member
>> 
>>             my Str %h = A => "a"
>>             {A => a}
>> 
>>             my int %h = A => 123
>>             native value types for hashes not yet implemented. Sorry.
>> 

On 2020-01-15 18:27, yary wrote:
> Capital I in Int, to not use native type
> 
>> my Int %h = A => 123
> 
> {A => 123}
> 
> 
> -y

Hi Yary,

Updated and awesome!  Thank you!

Is Int

    https://docs.raku.org/type/Int
    Int objects store integral numbers of arbitrary size

one of those "Magic" variables that is unbounded, meaning
I can have a 1024 bit integer if I choose?

-T
0
perl6
1/16/2020 3:28:18 AM
--000000000000006831059c3b4f88
Content-Type: text/plain; charset="UTF-8"

Thanks ToddAndMargo

Perhaps I have some questions to help improve the docs (I think):

1- You told about arrays of hashes, in Perl5 the opposite (hashes of
arrays) is quite fuzzy. Then, in Raku, how do I deal with hashes of arrays?

2 - "[...]say %h<a b>:p;   # note: no comma between the a and the b[...]",
that is interesting because using comma or semi-coma I had different
behavior.

perl6 -e 'my %h = a => "x", b=>"r", c=>"z"; say %h<a c>:p'
perl6 -e 'my %h = a => "x", b=>"r", c=>"z"; say %h<a, c>:p'
perl6 -e 'my %h = a => "x", b=>"r", c=>"z"; say %h<a; c>:p'

Sure, you notice I used "perl6" instead "raku". I'm not updated.



On Wed, Jan 15, 2020 at 10:28 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Wed, Jan 15, 2020 at 6:00 PM ToddAndMargo via perl6-users
> >> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> >>
> >>     A recent addition to my hashes keeper:
> >>
> >>
> >>          Confining hashes:
> >>          Note: as of 2020-01-15, confining only works with Str.
> >>                And you must confine the entire hash, not each member
> >>
> >>             my Str %h = A => "a"
> >>             {A => a}
> >>
> >>             my int %h = A => 123
> >>             native value types for hashes not yet implemented. Sorry.
> >>
>
> On 2020-01-15 18:27, yary wrote:
> > Capital I in Int, to not use native type
> >
> >> my Int %h = A => 123
> >
> > {A => 123}
> >
> >
> > -y
>
> Hi Yary,
>
> Updated and awesome!  Thank you!
>
> Is Int
>
>     https://docs.raku.org/type/Int
>     Int objects store integral numbers of arbitrary size
>
> one of those "Magic" variables that is unbounded, meaning
> I can have a 1024 bit integer if I choose?
>
> -T
>


-- 
Aureliano Guedes
skype: aureliano.guedes
contato:  (11) 94292-6110
whatsapp +5511942926110

--000000000000006831059c3b4f88
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Thanks=C2=A0ToddAndMargo<div><br></div><div>Perhaps I have=
 some questions=C2=A0to help improve the docs (I think):</div><div><br></di=
v><div>1- You told about arrays of hashes, in Perl5 the opposite=C2=A0(hash=
es of arrays) is quite fuzzy. Then, in Raku, how do I deal with hashes of a=
rrays?=C2=A0</div><div><br></div><div>2 - &quot;[...]say %h&lt;a b&gt;:p;=
=C2=A0 =C2=A0# note: no comma between the a and the b[...]&quot;, that is i=
nteresting because using comma or semi-coma I had different behavior.</div>=
<div><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div>p=
erl6 -e &#39;my %h =3D a =3D&gt; &quot;x&quot;, b=3D&gt;&quot;r&quot;, c=3D=
&gt;&quot;z&quot;; say %h&lt;a c&gt;:p&#39;<br></div><div>perl6 -e &#39;my =
%h =3D a =3D&gt; &quot;x&quot;, b=3D&gt;&quot;r&quot;, c=3D&gt;&quot;z&quot=
;; say %h&lt;a, c&gt;:p&#39;<br></div><div>perl6 -e &#39;my %h =3D a =3D&gt=
; &quot;x&quot;, b=3D&gt;&quot;r&quot;, c=3D&gt;&quot;z&quot;; say %h&lt;a;=
 c&gt;:p&#39;<br></div></blockquote>Sure, you notice I used &quot;perl6&quo=
t; instead &quot;raku&quot;. I&#39;m not updated.</div><div><br></div><div>=
<br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gm=
ail_attr">On Wed, Jan 15, 2020 at 10:28 PM ToddAndMargo via perl6-users &lt=
;<a href=3D"mailto:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote=
:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.=
8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">&gt;&gt; On We=
d, Jan 15, 2020 at 6:00 PM ToddAndMargo via perl6-users <br>
&gt;&gt; &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl=
6-users@perl.org</a> &lt;mailto:<a href=3D"mailto:perl6-users@perl.org" tar=
get=3D"_blank">perl6-users@perl.org</a>&gt;&gt; wrote:<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0A recent addition to my hashes keeper:<br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Confining hashes:<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Note: as of 2020-01-15, confinin=
g only works with Str.<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 And you mus=
t confine the entire hash, not each member<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my Str %h =3D A =3D=
&gt; &quot;a&quot;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{A =3D&gt; a}<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my int %h =3D A =3D=
&gt; 123<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0native value types =
for hashes not yet implemented. Sorry.<br>
&gt;&gt; <br>
<br>
On 2020-01-15 18:27, yary wrote:<br>
&gt; Capital I in Int, to not use native type<br>
&gt; <br>
&gt;&gt; my Int %h =3D A =3D&gt; 123<br>
&gt; <br>
&gt; {A =3D&gt; 123}<br>
&gt; <br>
&gt; <br>
&gt; -y<br>
<br>
Hi Yary,<br>
<br>
Updated and awesome!=C2=A0 Thank you!<br>
<br>
Is Int<br>
<br>
=C2=A0 =C2=A0 <a href=3D"https://docs.raku.org/type/Int" rel=3D"noreferrer"=
 target=3D"_blank">https://docs.raku.org/type/Int</a><br>
=C2=A0 =C2=A0 Int objects store integral numbers of arbitrary size<br>
<br>
one of those &quot;Magic&quot; variables that is unbounded, meaning<br>
I can have a 1024 bit integer if I choose?<br>
<br>
-T<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div><div=
 dir=3D"ltr"><div><div dir=3D"ltr"><div style=3D"text-align:center">Aurelia=
no Guedes</div><div style=3D"text-align:center"></div><div style=3D"text-al=
ign:center">skype: aureliano.guedes</div><div style=3D"text-align:center">c=
ontato: =C2=A0(11) 94292-6110</div><div style=3D"text-align:center">whatsap=
p +5511942926110</div></div></div></div></div></div></div></div></div>

--000000000000006831059c3b4f88--
0
guedes
1/16/2020 5:43:34 AM
--00000000000090aaf4059c3b9f55
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

> my Int $oK =3D 2**1024

179769313486231590772930519078902473361797697894230657273430081157732675805=
500963132708477322407536021120113879871393357658789768814416622492847430639=
474124377767893424865485276302219601246094119453082952085005768838150682342=
462881473913110540827237163350510684586298239947245938479716304835356329624=
224137216

> my int $no =3D 2**77

Cannot unbox 78 bit wide bigint into native integer


-y

>
>

--00000000000090aaf4059c3b9f55
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><br><div><p style=3D"mar=
gin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:M=
enlo;color:rgb(0,0,0)"><span style=3D"font-variant-ligatures:no-common-liga=
tures">&gt; my Int $oK =3D 2**1024</span></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:norma=
l;font-family:Menlo;color:rgb(0,0,0)"><span style=3D"font-variant-ligatures=
:no-common-ligatures">17976931348623159077293051907890247336179769789423065=
727343008115773267580550096313270847732240753602112011387987139335765878976=
881441662249284743063947412437776789342486548527630221960124609411945308295=
208500576883815068234246288147391311054082723716335051068458629823994724593=
8479716304835356329624224137216</span></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:norma=
l;font-family:Menlo;color:rgb(0,0,0)"><span style=3D"font-variant-ligatures=
:no-common-ligatures">&gt; my int $no =3D 2**77</span></p>
<p style=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:norma=
l;font-family:Menlo;color:rgb(0,0,0)"><span style=3D"font-variant-ligatures=
:no-common-ligatures">Cannot unbox 78 bit wide bigint into native integer</=
span></p></div><div><span style=3D"font-variant-ligatures:no-common-ligatur=
es"><br></span></div><div><br clear=3D"all"><div><div dir=3D"ltr" class=3D"=
gmail_signature">-y<br></div></div></div></div></div><div class=3D"gmail_qu=
ote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,2=
04);padding-left:1ex"><br>
</blockquote></div></div>

--00000000000090aaf4059c3b9f55--
0
not
1/16/2020 6:06:06 AM
On 2020-01-15 21:43, Aureliano Guedes wrote:
> Thanks=C2=A0ToddAndMargo
>=20
> Perhaps I have some questions=C2=A0to help improve the docs (I think):
>=20
> 1- You told about arrays of hashes, in Perl5 the opposite=C2=A0(hashes =
of=20
> arrays) is quite fuzzy. Then, in Raku, how do I deal with hashes of arr=
ays?
>=20
> 2 - "[...]say %h<a b>:p;=C2=A0 =C2=A0# note: no comma between the a and=
 the=20
> b[...]", that is interesting because using comma or semi-coma I had=20
> different behavior.
>=20
>     perl6 -e 'my %h =3D a =3D> "x", b=3D>"r", c=3D>"z"; say %h<a c>:p'
>     perl6 -e 'my %h =3D a =3D> "x", b=3D>"r", c=3D>"z"; say %h<a, c>:p'=

>     perl6 -e 'my %h =3D a =3D> "x", b=3D>"r", c=3D>"z"; say %h<a; c>:p'=

>=20
> Sure, you notice I used "perl6" instead "raku". I'm not updated.

Hi Aureliano,

Hmmm.  Interesting.  Never used hashes of arrays. I am
at a loss.

What would be the usage?


Tip: at the command line, enter "perl6" by itself.
It will open up what is called REPL.  It is like a
scratch pad to test code.  Your code looks like this
in REPL.

$ raku
To exit type 'exit' or '^D'
 > my %h =3D a =3D> "x", b=3D>"r", c=3D>"z"; say %h<a c>:p
(a =3D> x c =3D> z)
 > my %h =3D a =3D> "x", b=3D>"r", c=3D>"z"; say %h<a, c>:p
(c =3D> z)
 > my %h =3D a =3D> "x", b=3D>"r", c=3D>"z"; say %h<a; c>:p
(c =3D> z)
 >

Currently it borks on constrained values (my int32 $x).
It has an open bug on it:

$ raku
To exit type 'exit' or '^D'
 > my int32 $x;
0
 > say $x
Bytecode validation error at offset 148, instruction 23:
operand type 32 does not match register type 24 for op getlex_ni in=20
frame <unit>

One of the guys on the group told me about REPL and I
LOVE IT!

-T

On my system (Fedora 31):

$ raku -v
This is Rakudo version 2019.07.1 built on MoarVM version
2019.07.1 implementing Perl 6.d.

$ rpm -qa rakudo*
rakudo-pkg-2019.07.1-03.x86_64

$ alias p6
alias p6=3D'perl6 -e'

$ which raku
/usr/bin/raku

$ which perl6
/usr/bin/perl6

$ ls -al /usr/bin/raku
lrwxrwxrwx. 1 root root 25 Dec 25 14:36 /usr/bin/raku ->=20
/opt/rakudo-pkg/bin/perl6

$ ls -al /usr/bin/perl6
lrwxrwxrwx. 1 root root 25 Nov  3 14:53 /usr/bin/perl6 ->=20
/opt/rakudo-pkg/bin/perl6
0
perl6
1/16/2020 6:17:51 AM
--0000000000006838df059c3dbd52
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

 > one of those "Magic" variables that is unbounded, meaning
> I can have a 1024 bit integer if I choose?

Yeah, and even a 1024-digit integer, or much larger, if so you wish.



Le jeu. 16 janv. 2020 =C3=A0 04:28, ToddAndMargo via perl6-users <
perl6-users@perl.org> a =C3=A9crit :

> >> On Wed, Jan 15, 2020 at 6:00 PM ToddAndMargo via perl6-users
> >> <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:
> >>
> >>     A recent addition to my hashes keeper:
> >>
> >>
> >>          Confining hashes:
> >>          Note: as of 2020-01-15, confining only works with Str.
> >>                And you must confine the entire hash, not each member
> >>
> >>             my Str %h =3D A =3D> "a"
> >>             {A =3D> a}
> >>
> >>             my int %h =3D A =3D> 123
> >>             native value types for hashes not yet implemented. Sorry.
> >>
>
> On 2020-01-15 18:27, yary wrote:
> > Capital I in Int, to not use native type
> >
> >> my Int %h =3D A =3D> 123
> >
> > {A =3D> 123}
> >
> >
> > -y
>
> Hi Yary,
>
> Updated and awesome!  Thank you!
>
> Is Int
>
>     https://docs.raku.org/type/Int
>     Int objects store integral numbers of arbitrary size
>
> one of those "Magic" variables that is unbounded, meaning
> I can have a 1024 bit integer if I choose?
>
> -T
>

--0000000000006838df059c3dbd52
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">
&gt; one of those &quot;Magic&quot; variables that is unbounded, meaning<br=
><div>
&gt; I can have a 1024 bit integer if I choose? <br></div><div><br></div><d=
iv>Yeah, and even a 1024-digit integer, or much larger, if so you wish.</di=
v><div><br></div><div><br></div></div><br><div class=3D"gmail_quote"><div d=
ir=3D"ltr" class=3D"gmail_attr">Le=C2=A0jeu. 16 janv. 2020 =C3=A0=C2=A004:2=
8, ToddAndMargo via perl6-users &lt;<a href=3D"mailto:perl6-users@perl.org"=
>perl6-users@perl.org</a>&gt; a =C3=A9crit=C2=A0:<br></div><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid r=
gb(204,204,204);padding-left:1ex">&gt;&gt; On Wed, Jan 15, 2020 at 6:00 PM =
ToddAndMargo via perl6-users <br>
&gt;&gt; &lt;<a href=3D"mailto:perl6-users@perl.org" target=3D"_blank">perl=
6-users@perl.org</a> &lt;mailto:<a href=3D"mailto:perl6-users@perl.org" tar=
get=3D"_blank">perl6-users@perl.org</a>&gt;&gt; wrote:<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0A recent addition to my hashes keeper:<br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Confining hashes:<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Note: as of 2020-01-15, confinin=
g only works with Str.<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 And you mus=
t confine the entire hash, not each member<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my Str %h =3D A =3D=
&gt; &quot;a&quot;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{A =3D&gt; a}<br>
&gt;&gt; <br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0my int %h =3D A =3D=
&gt; 123<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0native value types =
for hashes not yet implemented. Sorry.<br>
&gt;&gt; <br>
<br>
On 2020-01-15 18:27, yary wrote:<br>
&gt; Capital I in Int, to not use native type<br>
&gt; <br>
&gt;&gt; my Int %h =3D A =3D&gt; 123<br>
&gt; <br>
&gt; {A =3D&gt; 123}<br>
&gt; <br>
&gt; <br>
&gt; -y<br>
<br>
Hi Yary,<br>
<br>
Updated and awesome!=C2=A0 Thank you!<br>
<br>
Is Int<br>
<br>
=C2=A0 =C2=A0 <a href=3D"https://docs.raku.org/type/Int" rel=3D"noreferrer"=
 target=3D"_blank">https://docs.raku.org/type/Int</a><br>
=C2=A0 =C2=A0 Int objects store integral numbers of arbitrary size<br>
<br>
one of those &quot;Magic&quot; variables that is unbounded, meaning<br>
I can have a 1024 bit integer if I choose?<br>
<br>
-T<br>
</blockquote></div>

--0000000000006838df059c3dbd52--
0
perl6
1/16/2020 8:38:31 AM
On 2020-01-16 00:38, Laurent Rosenfeld via perl6-users wrote:
>  > one of those "Magic" variables that is unbounded, meaning
>  > I can have a 1024 bit integer if I choose?
> 
> Yeah, and even a 1024-digit integer, or much larger, if so you wish.

I love it!

At some point, I love to know how Larry did it.
0
perl6
1/16/2020 5:23:09 PM
New addition to my hash keeper:


"returns" hash on a sub declaration:
     Note: "Associative" will return a hash or a map or even a pair
     > sub x() returns Associative { my %h= A=>"a"; return %h}
     &x
     > x
     {A => a}

     > sub x(--> Hash) { my %h= A=>"a", B=>"b"; return %h}
     &x
     > x
     {A => a, B => b}
     >

     > sub x() returns Hash { my %h= A=>"a"; return %h}
     &x
     > x
     {A => a}
0
perl6
1/21/2020 4:31:50 PM
Reply: