Re: stashing an array in a hash and yanking it back out

2020-03-19 Thread William Michels via perl6-users
Hi all,

Andy Bach contacted me off list, to say my postscript comment about
"prepending" (versus "appending") to a hash object was nonsensical. I
agree.

Hashes in Raku/Perl6 are guaranteed to be unordered upon return. So
once they are declared, it doesn't make sense to think of them as a
(double-ended) linear array of pairs.

--Bill.

P.S. Link to the ",=" Postfix operator:

https://docs.raku.org/routine/,=





On Thu, Mar 19, 2020 at 10:33 AM William Michels  wrote:
>
> Okay, here's another (simpler?) approach using the ",= " postfix operator:
>
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> > my %stash;
> {}
> > my @monsters = << godzilla grendel wormface blob >>;
> [godzilla grendel wormface blob]
> > my @rabbits = << bugs peter easter >>;
> [bugs peter easter]
> > %stash ,= monsters => @monsters
> {monsters => [godzilla grendel wormface blob]}
> > %stash ,= :@rabbits
> {monsters => [godzilla grendel wormface blob], rabbits => [bugs peter easter]}
> > say %stash
> {monsters => [godzilla grendel wormface blob], rabbits => [bugs peter easter]}
> > exit
> mbook:~ homedir$ perl6 -v
> This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
> implementing Perl 6.d.
>
> HTH, Bill.
>
> PS. Note, above shows how to 'postfix' (i.e. append), but I'm still
> unclear on how to prepend to a pre-existing hash.
>
>
> On Tue, Mar 17, 2020 at 11:15 AM Joseph Brenner  wrote:
> >
> > Yes you're right: I could've sworn I tried that in the repl a minute
> > ago and it worked, but actually it's a no-op and appends nothing to
> > the hash.
> >
> > This is okay, doing it the other way (without the inner parens around
> > the colonpair) is not:
> >
> > ny %stash;
> > my @monsters = << godzilla grendel wormface blob >>;
> > my @rabbits = << bugs peter easter >>;
> >
> > %stash.append( (:@monsters) );
> > %stash.append( (:@rabbits) );
> >
> > say %stash;
> >
> >
> > On 3/17/20, Vadim Belman  wrote:
> > >
> > > Joseph, you've got yourself into a trap I fell into yesterday.
> > > %stash.append( :@stuff ) syntax is about calling append method with a 
> > > named
> > > parameter stuff whereas append works with positionals only. So, your case
> > > should be written:
> > >
> > > %stash.append( (:@stuff) );
> > >
> > > Which is apparently more cumbersome. In either case, use of colons is not
> > > always about saving a character or two. Sometimes it's about readability,
> > > sometimes about elegance. Overuse is surely bad, but overuse of anything 
> > > is
> > > bad, for that matter. :)
> > >
> > > Best regards,
> > > Vadim Belman
> > >
> > >> On Mar 17, 2020, at 1:09 PM, Joseph Brenner  wrote:
> > >>
> > >>> Though I've no idea what those colons are/are not doing.
> > >>
> > >> Those are "colon pairs" (which I've relearned around three times now...):
> > >>
> > >>   https://docs.raku.org/language/glossary#index-entry-Colon_Pair
> > >> 
> > >>
> > >> Except for this colon:
> > >>
> > >>  %stash.append: (rocks => @rocks);
> > >>
> > >> Which is a short hand for this:
> > >>
> > >>  %stash.append( (rocks => @rocks) );
> > >>
> > >> As an aside: it's a minor style point, but I think a lot of
> > >> us overuse that trick-- it saves a character, but the explicit
> > >> parens are more flexible.
> > >>
> > >> Notably this works fine, so here it doesn't even save any
> > >> characters:
> > >>
> > >>  %stash.append( :@stuff );
> > >>
> > >>
> > >
> > >


Re: stashing an array in a hash and yanking it back out

2020-03-19 Thread William Michels via perl6-users
Okay, here's another (simpler?) approach using the ",= " postfix operator:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my %stash;
{}
> my @monsters = << godzilla grendel wormface blob >>;
[godzilla grendel wormface blob]
> my @rabbits = << bugs peter easter >>;
[bugs peter easter]
> %stash ,= monsters => @monsters
{monsters => [godzilla grendel wormface blob]}
> %stash ,= :@rabbits
{monsters => [godzilla grendel wormface blob], rabbits => [bugs peter easter]}
> say %stash
{monsters => [godzilla grendel wormface blob], rabbits => [bugs peter easter]}
> exit
mbook:~ homedir$ perl6 -v
This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
implementing Perl 6.d.

HTH, Bill.

PS. Note, above shows how to 'postfix' (i.e. append), but I'm still
unclear on how to prepend to a pre-existing hash.


On Tue, Mar 17, 2020 at 11:15 AM Joseph Brenner  wrote:
>
> Yes you're right: I could've sworn I tried that in the repl a minute
> ago and it worked, but actually it's a no-op and appends nothing to
> the hash.
>
> This is okay, doing it the other way (without the inner parens around
> the colonpair) is not:
>
> ny %stash;
> my @monsters = << godzilla grendel wormface blob >>;
> my @rabbits = << bugs peter easter >>;
>
> %stash.append( (:@monsters) );
> %stash.append( (:@rabbits) );
>
> say %stash;
>
>
> On 3/17/20, Vadim Belman  wrote:
> >
> > Joseph, you've got yourself into a trap I fell into yesterday.
> > %stash.append( :@stuff ) syntax is about calling append method with a named
> > parameter stuff whereas append works with positionals only. So, your case
> > should be written:
> >
> > %stash.append( (:@stuff) );
> >
> > Which is apparently more cumbersome. In either case, use of colons is not
> > always about saving a character or two. Sometimes it's about readability,
> > sometimes about elegance. Overuse is surely bad, but overuse of anything is
> > bad, for that matter. :)
> >
> > Best regards,
> > Vadim Belman
> >
> >> On Mar 17, 2020, at 1:09 PM, Joseph Brenner  wrote:
> >>
> >>> Though I've no idea what those colons are/are not doing.
> >>
> >> Those are "colon pairs" (which I've relearned around three times now...):
> >>
> >>   https://docs.raku.org/language/glossary#index-entry-Colon_Pair
> >> 
> >>
> >> Except for this colon:
> >>
> >>  %stash.append: (rocks => @rocks);
> >>
> >> Which is a short hand for this:
> >>
> >>  %stash.append( (rocks => @rocks) );
> >>
> >> As an aside: it's a minor style point, but I think a lot of
> >> us overuse that trick-- it saves a character, but the explicit
> >> parens are more flexible.
> >>
> >> Notably this works fine, so here it doesn't even save any
> >> characters:
> >>
> >>  %stash.append( :@stuff );
> >>
> >>
> >
> >


Re: stashing an array in a hash and yanking it back out

2020-03-17 Thread Joseph Brenner
Yes you're right: I could've sworn I tried that in the repl a minute
ago and it worked, but actually it's a no-op and appends nothing to
the hash.

This is okay, doing it the other way (without the inner parens around
the colonpair) is not:

ny %stash;
my @monsters = << godzilla grendel wormface blob >>;
my @rabbits = << bugs peter easter >>;

%stash.append( (:@monsters) );
%stash.append( (:@rabbits) );

say %stash;


On 3/17/20, Vadim Belman  wrote:
>
> Joseph, you've got yourself into a trap I fell into yesterday.
> %stash.append( :@stuff ) syntax is about calling append method with a named
> parameter stuff whereas append works with positionals only. So, your case
> should be written:
>
> %stash.append( (:@stuff) );
>
> Which is apparently more cumbersome. In either case, use of colons is not
> always about saving a character or two. Sometimes it's about readability,
> sometimes about elegance. Overuse is surely bad, but overuse of anything is
> bad, for that matter. :)
>
> Best regards,
> Vadim Belman
>
>> On Mar 17, 2020, at 1:09 PM, Joseph Brenner  wrote:
>>
>>> Though I've no idea what those colons are/are not doing.
>>
>> Those are "colon pairs" (which I've relearned around three times now...):
>>
>>   https://docs.raku.org/language/glossary#index-entry-Colon_Pair
>> 
>>
>> Except for this colon:
>>
>>  %stash.append: (rocks => @rocks);
>>
>> Which is a short hand for this:
>>
>>  %stash.append( (rocks => @rocks) );
>>
>> As an aside: it's a minor style point, but I think a lot of
>> us overuse that trick-- it saves a character, but the explicit
>> parens are more flexible.
>>
>> Notably this works fine, so here it doesn't even save any
>> characters:
>>
>>  %stash.append( :@stuff );
>>
>>
>
>


Re: stashing an array in a hash and yanking it back out

2020-03-17 Thread Vadim Belman

Joseph, you've got yourself into a trap I fell into yesterday. %stash.append( 
:@stuff ) syntax is about calling append method with a named parameter stuff 
whereas append works with positionals only. So, your case should be written:

%stash.append( (:@stuff) );

Which is apparently more cumbersome. In either case, use of colons is not 
always about saving a character or two. Sometimes it's about readability, 
sometimes about elegance. Overuse is surely bad, but overuse of anything is 
bad, for that matter. :)

Best regards,
Vadim Belman

> On Mar 17, 2020, at 1:09 PM, Joseph Brenner  wrote:
> 
>> Though I've no idea what those colons are/are not doing.
> 
> Those are "colon pairs" (which I've relearned around three times now...):
> 
>   https://docs.raku.org/language/glossary#index-entry-Colon_Pair 
> 
> 
> Except for this colon:
> 
>  %stash.append: (rocks => @rocks);
> 
> Which is a short hand for this:
> 
>  %stash.append( (rocks => @rocks) );
> 
> As an aside: it's a minor style point, but I think a lot of
> us overuse that trick-- it saves a character, but the explicit
> parens are more flexible.
> 
> Notably this works fine, so here it doesn't even save any
> characters:
> 
>  %stash.append( :@stuff );
> 
> 



Re: stashing an array in a hash and yanking it back out

2020-03-17 Thread Joseph Brenner
> Though I've no idea what those colons are/are not doing.

Those are "colon pairs" (which I've relearned around three times now...):

   https://docs.raku.org/language/glossary#index-entry-Colon_Pair

Except for this colon:

  %stash.append: (rocks => @rocks);

Which is a short hand for this:

  %stash.append( (rocks => @rocks) );

As an aside: it's a minor style point, but I think a lot of
us overuse that trick-- it saves a character, but the explicit
parens are more flexible.

Notably this works fine, so here it doesn't even save any
characters:

  %stash.append( :@stuff );


On 3/16/20, Andy Bach  wrote:
> Vadim clarified for us, off-list:
>> So, you basically needed:
> my %h = :a(1); %h.append: (:b(2));
>
>> Am I correct?
> I think so, I mean, I believe the append method(?) for hashes would solve
> the problem the "whatever star" was attempted to be used for - so:
>> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
> [godzilla grendel wormface blob fingfangfoom tingler]
>> my @rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
>> my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>>  %stash.append: (:rocks(@rocks));
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks =>
> [marble sandstone granite chert pumice limestone]}
> Or:
>> my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>> %stash.append: (:rocks => @rocks);
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks
> True => [marble sandstone granite chert pumice limestone]}
> Or:
>> my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>> %stash.append: (rocks => @rocks);
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks =>
> [marble sandstone granite chert pumice limestone]}
>
> Though I've no idea what those colons are/are not doing.  And we can get to
> those "inner" array elements via
>> say %stash[1]
> sandstone
>
>
>
> 
> From: Vadim Belman 
> Sent: Friday, March 13, 2020 12:50 PM
> To: Andy Bach 
> Cc: William Michels via perl6-users ; Joseph Brenner
> ; Timo Paulssen ; yary
> 
> Subject: Re: stashing an array in a hash and yanking it back out
>
>
> There is no mystery whatsoever.
>
> Consider the following:
>
> my %h = "a", 1; # {a => 1}
>
> Then consider this:
>
> say *, *; # **
>
>
> and also:
>
> say *.VAR.WHAT; # (Whatever)
>
> Taking into account that => has tighter precedence than , what you get in:
>
> my %h = *, a => [1,2,3];
>
> is actually the following data structure:
>
> %( Whatever => Pair )
>
> Regarding your use of postcircumfix [ ] on the data, you use it on Pair.
>
> Best regards,
> Vadim Belman
>
> On Mar 13, 2020, at 11:52 AM, Andy Bach
> mailto:andy_b...@wiwb.uscourts.gov>> wrote:
>
>> my  %stash = monsters => @monsters, rocks => @rocks
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks =>
> [marble sandstone granite chert pumice limestone]}
>> my @more_rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
>> my  %stash = *, morerocks => @rocks
> {* => morerocks => [marble sandstone granite chert pumice limestone]}
>> say %stash{*}
> (morerocks => [marble sandstone granite chert pumice limestone])
>
> So, I'm guessing the display
> {* => morerocks => [marble sandstone granite chert pumice limestone]}
>
> really means something like
> {* => (morerocks => [marble sandstone granite chert pumice limestone])}
>
> maybe?
>> say @(%stash{*})
> (morerocks => [marble sandstone granite chert pumice limestone])
>> say @(%stash{*}).[0]
> morerocks => [marble sandstone granite chert pumice limestone]
>> say @(%stash{*}).[1]
> Nil
>> say @(%stash{*}).[0].{morerocks}
> ===SORRY!=== Error while compiling:
> Undeclared routine:
> morerocks used at line 1
>
>> say @(%stash{*}).[0].[0]
> morerocks => [marble sandstone granite chert pumice limestone]
>> say @(%stash{*}).[0].[1]
> Index out of range. Is: 1, should be in 0..0
>   in block  at  line 1
>
>> say @(%stash{*}).[0].[0].perl
> :morerocks(["marble", "sandstone", "granite", "chert", "pumice",
> "limestone"])
>> say @(%stash{*}).[0].perl
> :morerocks(["marble", "sandstone", "granite", "chert", "pumice",
> "limestone"])
>
>
> I dunno.
>
> 
> From: William Michels via perl6-users
> mailto:perl6-users@perl.org>>
> Sent: Thursday, March 12, 2020 5:44 PM
> To: perl6-users mailto:perl6-users@perl.org>>
> Cc: Joseph Brenner mailto:doom...@gmail.com>>; Timo
> Paulssen mailto:t...@wakelift.de>>; yary
> mailto:not@gmail.com>>
> Subject: Re: stashing an array in a hash and yanking it back out
>
> Thanks yary! The code you posted works perfectly.
>
> Okay, one last question. I tried to use the 'DRY' principle to add
> things 

Re: stashing an array in a hash and yanking it back out

2020-03-17 Thread Joseph Brenner
Thanks, this is indeed the trick:

> Ok, clear enough. This is as simple as:

> %stash.append: (:@greek);



On 3/17/20, Vadim Belman  wrote:
> My reply to Joseph went off the list too. I copy it over here. Here is the
> key quote from Joseph's email I was answering to:
>
> So doing that with append would be like this:
>
>  %stash.append: (:greek(@greek));
>
> William Michels was wondering if there was a way to avoid
> repeating the name twice, speculating that there might be
> some way to do that with a 'whateva' *.
>
> My answer follows:
>
> Ok, clear enough. This is as simple as:
>
> %stash.append: (:@greek);
>
> Roughly, colon op doesn't care about sigils and twigils. It takes a symbol
> and creates a pair with the key of the symbol. A good example with a bit of
> Raku charm:
>
> class Foo {
> has @.attr = ;
> method foo { %(:@.attr) }
> }
> say Foo.new.foo; # {attr => [a b c]}
>
> Best regards,
> Vadim Belman
>
>> On Mar 16, 2020, at 6:44 PM, Andy Bach 
>> wrote:
>>
>> Vadim clarified for us, off-list:
>> > So, you basically needed:
>> my %h = :a(1); %h.append: (:b(2));
>>
>> > Am I correct?
>> I think so, I mean, I believe the append method(?) for hashes would solve
>> the problem the "whatever star" was attempted to be used for - so:
> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler
> > >>;
> [godzilla grendel wormface blob fingfangfoom tingler]
> > my @rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
> > my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> >  %stash.append: (:rocks(@rocks));
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler],
> rocks => [marble sandstone granite chert pumice limestone]}
> Or:
> > my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> > %stash.append: (:rocks => @rocks);
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler],
> rocks True => [marble sandstone granite chert pumice limestone]}
> Or:
> > my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> > %stash.append: (rocks => @rocks);
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler],
> rocks => [marble sandstone granite chert pumice limestone]}
>
>> Though I've no idea what those colons are/are not doing.  And we can get
>> to those "inner" array elements via
>> > say %stash[1]
>> sandstone
>>
>>
>>
>> From: Vadim Belman 
>> Sent: Friday, March 13, 2020 12:50 PM
>> To: Andy Bach 
>> Cc: William Michels via perl6-users ; Joseph Brenner
>> ; Timo Paulssen ; yary
>> 
>> Subject: Re: stashing an array in a hash and yanking it back out
>>
>>
>> There is no mystery whatsoever.
>>
>> Consider the following:
>>
>> my %h = "a", 1; # {a => 1}
>>
>> Then consider this:
>>
>> say *, *; # **
>>
>>
>> and also:
>>
>> say *.VAR.WHAT; # (Whatever)
>>
>> Taking into account that => has tighter precedence than , what you get
>> in:
>>
>> my %h = *, a => [1,2,3];
>>
>> is actually the following data structure:
>>
>> %( Whatever => Pair )
>>
>> Regarding your use of postcircumfix [ ] on the data, you use it on Pair.
>>
>> Best regards,
>> Vadim Belman
>>
>>> On Mar 13, 2020, at 11:52 AM, Andy Bach >> > wrote:
>>>
>>> > my  %stash = monsters => @monsters, rocks => @rocks
>>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks
>>> => [marble sandstone granite chert pumice limestone]}
>>> > my @more_rocks = << marble sandstone granite chert pumice limestone >>
>>> [marble sandstone granite chert pumice limestone]
>>> > my  %stash = *, morerocks => @rocks
>>> {* => morerocks => [marble sandstone granite chert pumice limestone]}
>>> > say %stash{*}
>>> (morerocks => [marble sandstone granite chert pumice limestone])
>>>
>>> So, I'm guessing the display
>>> {* => morerocks => [marble sandstone granite chert pumice limestone]}
>>>
>>> really means something like
>>> {* => (morerocks => [marble sandstone granite chert pumice limestone])}
>>>
>>> maybe?
>>> > say @(%stash{*})
>>> (morerocks => [marble sandstone granite chert pumice limestone])
>>> > say @(%stash{*}).[0]
>>> morerocks => [marble sandstone granite chert pumice limestone]
>>> > say @(%stash{*}).[1]
>>> Nil
>>> > say @(%stash{*}).[0].{morerocks}
>>> ===SORRY!=== Error while compiling:
>>> Undeclared routine:
>>> morerocks used at line 1
>>>
>>> > say @(%stash{*}).[0].[0]
>>> morerocks => [marble sandstone granite chert pumice limestone]
>>> > say @(%stash{*}).[0].[1]
>>> Index out of range. Is: 1, should be in 0..0
>>>   in block  at  line 1
>>>
>>> > say @(%stash{*}).[0].[0].perl
>>> :morerocks(["marble", "sandstone", "granite", "chert", "pumice",
>>> "limestone"])
>>> > say @(%stash{*}).[0].perl
>>> :morerocks(["marble", 

Re: stashing an array in a hash and yanking it back out

2020-03-17 Thread yary
Vadim seems to have provided the definitive answer:

Ok, clear enough. This is as simple as:
> %stash.append: (:@greek);


Fwd: stashing an array in a hash and yanking it back out

2020-03-17 Thread Joseph Brenner
Sorry, I thought I was replying on list...

I was trying to remind that what William Michels was asking about was
a way to assign an array to a hash field named after the array, but
without manually typing the name twice.

These both work, but aren't what he was asking about:

  %stash{'greek'}= @greek;

   %stash.append: (:greek(@greek));


-- Forwarded message --
From: Joseph Brenner 
Date: Mon, 16 Mar 2020 14:10:01 -0700
Subject: Re: stashing an array in a hash and yanking it back out
To: Vadim Belman 

Vadim Belman wrote:

> So, you basically needed:
>
> my %h = :a(1); %h.append: (:b(2));
>
> Am I correct?
Well, not exactly.

The kind of thing I was doing is stashing the contents of an
array in a hash field with the same name:

  my @greek = << alpha beta gamma >>;
  %stash{'greek'}= @greek;

So doing that with append would be like this:

  %stash.append: (:greek(@greek));

William Michels was wondering if there was a way to avoid
repeating the name twice, speculating that there might be
some way to do that with a 'whateva' *.

My personal take would be that even if there's a way to do that
that I'm missing, it's probably a little too clever.  You can
over do things like "DRY"...  It's pretty clear at a glance what
a line like this is trying to do:

  %stash{'greek'} = @greek;



On 3/16/20, Vadim Belman  wrote:
> So, you basically needed:
>
> my %h = :a(1); %h.append: (:b(2));
>
> Am I correct?
>
> Best regards,
> Vadim Belman
>
>> On Mar 16, 2020, at 11:13 AM, Andy Bach 
>> wrote:
>>
>> > Due to rather weird formatting in your message I hardly can understand
>> > what is it all about.
>> No worries,  I'm often quite befuddling, esp. when I think I'm being
>> extra-clear about things.  I was trying to include enough of the previous
>> thread, in context, to make any replies more coherent.  Then again, I'm
>> using Outlook and I never really know what it's going to do to my outgoing
>> msgs.
>>
>> It wasn't my idea to use the "*", Joseph, the original poster was thinking
>> they could save rekeying (or something) the current contents of the hash
>> by using the "*" in the assignment list, when adding a new pair without
>> specifying the key on the LHS. Whoops, it was William who tried the
>> "whatever star" problem.
>>
  However, (thinking that a 'whatever star' might
 reduce typing), I came up with an odd "ternary" structure. Can anyone
 explain the last line of code, below?

 mbook:~ homedir$ perl6
 To exit type 'exit' or '^D'
 > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler
 > >>;
 [godzilla grendel wormface blob fingfangfoom tingler]
 > my @rocks = << marble sandstone granite chert pumice limestone >>
 [marble sandstone granite chert pumice limestone]
 > my  %stash = monsters => @monsters
 {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
 > my %stash = *, rocks => @rocks;
 {* => rocks => [marble sandstone granite chert pumice limestone]}
>>
>> From: Vadim Belman 
>> Sent: Sunday, March 15, 2020 5:18 PM
>> To: Andy Bach 
>> Cc: William Michels via perl6-users ; Joseph Brenner
>> ; Timo Paulssen ; yary
>> 
>> Subject: Re: stashing an array in a hash and yanking it back out
>>
>> Due to rather weird formatting in your message I hardly can understand
>> what is it all about. But before you can find an answer on how to get the
>> array out of the hash, try answering the following question: why do you
>> use bare asterisk in the hash initialization? What is its purpose over
>> there? To me this looks like the key to all your issues.
>>
>> With regard to Pair type object, there is a little magic about it:
>>
>> my $p = a => [1,2]; say $p;
>>
>> Or, in your case that'd be something like:
>>
>> my %h = *, a => ; say %h<*>;
>>
>> Though I'd still insist on reconsidering how you do things.
>>
>> Best regards,
>> Vadim Belman
>>
>>> On Mar 15, 2020, at 5:41 PM, Andy Bach >> > wrote:
>>>
>>> >> really means something like
>>> {* => (morerocks => [marble sandstone granite chert pumice limestone])}
>>>
>>> > Taking into account that => has tighter precedence than , what you get
>>> > in:
>>> my %h = *, a => [1,2,3];
>>>
>>> > is actually the following data structure:
>>> %( Whatever => Pair )
>>>
>>> That's sort of what I said, or, at least, saw.
>>> > Regarding your use of postcircumfix [ ] on the data, you use it on
>>> > Pair.
>>>
>>> Not quite sure what this means, but is that how you'd get the [>> rocks>] array from %stash? I could get the pair back, but not the "inner"
>>> array of the pair's 2nd partner, so to speak:
>>> >> say @(%stash{*})
>>> (morerocks => [marble sandstone granite chert pumice limestone])
>>> >> say @(%stash{*}).[0]
>>> morerocks => [marble sandstone granite chert pumice limestone]
>>> >> say @(%stash{*}).[1]
>>> Nil
>>> >> say @(%stash{*}).[0].{morerocks}
>>> ===SORRY!=== Error while compiling:
>>> Undeclared routine:
>>>

Re: stashing an array in a hash and yanking it back out

2020-03-17 Thread Vadim Belman
My reply to Joseph went off the list too. I copy it over here. Here is the key 
quote from Joseph's email I was answering to:

So doing that with append would be like this:

 %stash.append: (:greek(@greek));

William Michels was wondering if there was a way to avoid
repeating the name twice, speculating that there might be
some way to do that with a 'whateva' *.

My answer follows:

Ok, clear enough. This is as simple as:

%stash.append: (:@greek);

Roughly, colon op doesn't care about sigils and twigils. It takes a symbol and 
creates a pair with the key of the symbol. A good example with a bit of Raku 
charm:

class Foo { 
has @.attr = ; 
method foo { %(:@.attr) } 
}
say Foo.new.foo; # {attr => [a b c]}

Best regards,
Vadim Belman

> On Mar 16, 2020, at 6:44 PM, Andy Bach  wrote:
> 
> Vadim clarified for us, off-list:
> > So, you basically needed:
> my %h = :a(1); %h.append: (:b(2));
> 
> > Am I correct?
> I think so, I mean, I believe the append method(?) for hashes would solve the 
> problem the "whatever star" was attempted to be used for - so:
 > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
 [godzilla grendel wormface blob fingfangfoom tingler]
 > my @rocks = << marble sandstone granite chert pumice limestone >>
 [marble sandstone granite chert pumice limestone]
 > my  %stash = monsters => @monsters
 {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
 >  %stash.append: (:rocks(@rocks));
 {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks 
 => [marble sandstone granite chert pumice limestone]}
 Or:
 > my  %stash = monsters => @monsters
 {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
 > %stash.append: (:rocks => @rocks);
 {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks 
 True => [marble sandstone granite chert pumice limestone]}
 Or:
 > my  %stash = monsters => @monsters
 {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
 > %stash.append: (rocks => @rocks);
 {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks 
 => [marble sandstone granite chert pumice limestone]}
 
> Though I've no idea what those colons are/are not doing.  And we can get to 
> those "inner" array elements via
> > say %stash[1]
> sandstone
> 
> 
> 
> From: Vadim Belman 
> Sent: Friday, March 13, 2020 12:50 PM
> To: Andy Bach 
> Cc: William Michels via perl6-users ; Joseph Brenner 
> ; Timo Paulssen ; yary 
> 
> Subject: Re: stashing an array in a hash and yanking it back out
>  
> 
> There is no mystery whatsoever.
> 
> Consider the following:
> 
> my %h = "a", 1; # {a => 1}
> 
> Then consider this:
> 
> say *, *; # **
> 
> 
> and also:
> 
> say *.VAR.WHAT; # (Whatever)
> 
> Taking into account that => has tighter precedence than , what you get in:
> 
> my %h = *, a => [1,2,3];
> 
> is actually the following data structure:
> 
> %( Whatever => Pair )
> 
> Regarding your use of postcircumfix [ ] on the data, you use it on Pair.
> 
> Best regards,
> Vadim Belman 
> 
>> On Mar 13, 2020, at 11:52 AM, Andy Bach > > wrote:
>> 
>> > my  %stash = monsters => @monsters, rocks => @rocks
>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
>> [marble sandstone granite chert pumice limestone]}
>> > my @more_rocks = << marble sandstone granite chert pumice limestone >>
>> [marble sandstone granite chert pumice limestone]
>> > my  %stash = *, morerocks => @rocks
>> {* => morerocks => [marble sandstone granite chert pumice limestone]}
>> > say %stash{*}
>> (morerocks => [marble sandstone granite chert pumice limestone])
>> 
>> So, I'm guessing the display
>> {* => morerocks => [marble sandstone granite chert pumice limestone]}
>> 
>> really means something like
>> {* => (morerocks => [marble sandstone granite chert pumice limestone])}
>> 
>> maybe?
>> > say @(%stash{*})
>> (morerocks => [marble sandstone granite chert pumice limestone])
>> > say @(%stash{*}).[0]
>> morerocks => [marble sandstone granite chert pumice limestone]
>> > say @(%stash{*}).[1]
>> Nil
>> > say @(%stash{*}).[0].{morerocks}
>> ===SORRY!=== Error while compiling:
>> Undeclared routine:
>> morerocks used at line 1
>> 
>> > say @(%stash{*}).[0].[0]
>> morerocks => [marble sandstone granite chert pumice limestone]
>> > say @(%stash{*}).[0].[1]
>> Index out of range. Is: 1, should be in 0..0
>>   in block  at  line 1
>> 
>> > say @(%stash{*}).[0].[0].perl
>> :morerocks(["marble", "sandstone", "granite", "chert", "pumice", 
>> "limestone"])
>> > say @(%stash{*}).[0].perl
>> :morerocks(["marble", "sandstone", "granite", "chert", "pumice", 
>> "limestone"])
>> 
>> 
>> I dunno.
>> 
>> From: William Michels via perl6-users > >
>> Sent: Thursday, March 12, 2020 5:44 PM
>> To: perl6-users mailto:perl6-users@perl.org>>
>> Cc: Joseph Brenner 

Re: stashing an array in a hash and yanking it back out

2020-03-16 Thread Andy Bach
Vadim clarified for us, off-list:
> So, you basically needed:
my %h = :a(1); %h.append: (:b(2));

> Am I correct?
I think so, I mean, I believe the append method(?) for hashes would solve the 
problem the "whatever star" was attempted to be used for - so:
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>  %stash.append: (:rocks(@rocks));
{monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
[marble sandstone granite chert pumice limestone]}
Or:
> my  %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> %stash.append: (:rocks => @rocks);
{monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks True 
=> [marble sandstone granite chert pumice limestone]}
Or:
> my  %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> %stash.append: (rocks => @rocks);
{monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
[marble sandstone granite chert pumice limestone]}

Though I've no idea what those colons are/are not doing.  And we can get to 
those "inner" array elements via
> say %stash[1]
sandstone




From: Vadim Belman 
Sent: Friday, March 13, 2020 12:50 PM
To: Andy Bach 
Cc: William Michels via perl6-users ; Joseph Brenner 
; Timo Paulssen ; yary 
Subject: Re: stashing an array in a hash and yanking it back out


There is no mystery whatsoever.

Consider the following:

my %h = "a", 1; # {a => 1}

Then consider this:

say *, *; # **


and also:

say *.VAR.WHAT; # (Whatever)

Taking into account that => has tighter precedence than , what you get in:

my %h = *, a => [1,2,3];

is actually the following data structure:

%( Whatever => Pair )

Regarding your use of postcircumfix [ ] on the data, you use it on Pair.

Best regards,
Vadim Belman

On Mar 13, 2020, at 11:52 AM, Andy Bach 
mailto:andy_b...@wiwb.uscourts.gov>> wrote:

> my  %stash = monsters => @monsters, rocks => @rocks
{monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
[marble sandstone granite chert pumice limestone]}
> my @more_rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = *, morerocks => @rocks
{* => morerocks => [marble sandstone granite chert pumice limestone]}
> say %stash{*}
(morerocks => [marble sandstone granite chert pumice limestone])

So, I'm guessing the display
{* => morerocks => [marble sandstone granite chert pumice limestone]}

really means something like
{* => (morerocks => [marble sandstone granite chert pumice limestone])}

maybe?
> say @(%stash{*})
(morerocks => [marble sandstone granite chert pumice limestone])
> say @(%stash{*}).[0]
morerocks => [marble sandstone granite chert pumice limestone]
> say @(%stash{*}).[1]
Nil
> say @(%stash{*}).[0].{morerocks}
===SORRY!=== Error while compiling:
Undeclared routine:
morerocks used at line 1

> say @(%stash{*}).[0].[0]
morerocks => [marble sandstone granite chert pumice limestone]
> say @(%stash{*}).[0].[1]
Index out of range. Is: 1, should be in 0..0
  in block  at  line 1

> say @(%stash{*}).[0].[0].perl
:morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"])
> say @(%stash{*}).[0].perl
:morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"])


I dunno.


From: William Michels via perl6-users 
mailto:perl6-users@perl.org>>
Sent: Thursday, March 12, 2020 5:44 PM
To: perl6-users mailto:perl6-users@perl.org>>
Cc: Joseph Brenner mailto:doom...@gmail.com>>; Timo Paulssen 
mailto:t...@wakelift.de>>; yary 
mailto:not@gmail.com>>
Subject: Re: stashing an array in a hash and yanking it back out

Thanks yary! The code you posted works perfectly.

Okay, one last question. I tried to use the 'DRY' principle to add
things to a hash. However, (thinking that a 'whatever star' might
reduce typing), I came up with an odd "ternary" structure. Can anyone
explain the last line of code, below?

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> my %stash = *, rocks => @rocks;
{* => rocks => [marble sandstone granite chert pumice limestone]}

Thanks, Bill.


On Wed, Mar 11, 2020 at 9:06 PM yary 
mailto:not@gmail.com>> wrote:
>
> The fat-arrow example makes sense, what this says
> 

Re: stashing an array in a hash and yanking it back out

2020-03-15 Thread Vadim Belman
Due to rather weird formatting in your message I hardly can understand what is 
it all about. But before you can find an answer on how to get the array out of 
the hash, try answering the following question: why do you use bare asterisk in 
the hash initialization? What is its purpose over there? To me this looks like 
the key to all your issues.

With regard to Pair type object, there is a little magic about it:

my $p = a => [1,2]; say $p;

Or, in your case that'd be something like:

my %h = *, a => ; say %h<*>;

Though I'd still insist on reconsidering how you do things.

Best regards,
Vadim Belman

> On Mar 15, 2020, at 5:41 PM, Andy Bach  wrote:
> 
> >> really means something like
> {* => (morerocks => [marble sandstone granite chert pumice limestone])}
> 
> > Taking into account that => has tighter precedence than , what you get in:
> my %h = *, a => [1,2,3];
> 
> > is actually the following data structure:
> %( Whatever => Pair )
> 
> That's sort of what I said, or, at least, saw.  
> > Regarding your use of postcircumfix [ ] on the data, you use it on Pair.
> 
> Not quite sure what this means, but is that how you'd get the [ rocks>] array from %stash? I could get the pair back, but not the "inner" 
> array of the pair's 2nd partner, so to speak:
> >> say @(%stash{*})
> (morerocks => [marble sandstone granite chert pumice limestone])
> >> say @(%stash{*}).[0]
> morerocks => [marble sandstone granite chert pumice limestone]
> >> say @(%stash{*}).[1]
> Nil
> >> say @(%stash{*}).[0].{morerocks}
> ===SORRY!=== Error while compiling:
> Undeclared routine:
> morerocks used at line 1
> 
> >> say @(%stash{*}).[0].[0]
> morerocks => [marble sandstone granite chert pumice limestone]
> 
> 
> a
> 
> From: Vadim Belman 
> Sent: Friday, March 13, 2020 12:50 PM
> To: Andy Bach 
> Cc: William Michels via perl6-users ; Joseph Brenner 
> ; Timo Paulssen ; yary 
> 
> Subject: Re: stashing an array in a hash and yanking it back out
>  
> 
> There is no mystery whatsoever.
> 
> Consider the following:
> 
> my %h = "a", 1; # {a => 1}
> 
> Then consider this:
> 
> say *, *; # **
> 
> 
> and also:
> 
> say *.VAR.WHAT; # (Whatever)
> 
> Taking into account that => has tighter precedence than , what you get in:
> 
> my %h = *, a => [1,2,3];
> 
> is actually the following data structure:
> 
> %( Whatever => Pair )
> 
> Regarding your use of postcircumfix [ ] on the data, you use it on Pair.
> 
> Best regards,
> Vadim Belman 
> 
>> On Mar 13, 2020, at 11:52 AM, Andy Bach > > wrote:
>> 
>> > my  %stash = monsters => @monsters, rocks => @rocks
>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
>> [marble sandstone granite chert pumice limestone]}
>> > my @more_rocks = << marble sandstone granite chert pumice limestone >>
>> [marble sandstone granite chert pumice limestone]
>> > my  %stash = *, morerocks => @rocks
>> {* => morerocks => [marble sandstone granite chert pumice limestone]}
>> > say %stash{*}
>> (morerocks => [marble sandstone granite chert pumice limestone])
>> 
>> So, I'm guessing the display
>> {* => morerocks => [marble sandstone granite chert pumice limestone]}
>> 
>> really means something like
>> {* => (morerocks => [marble sandstone granite chert pumice limestone])}
>> 
>> maybe?
>> > say @(%stash{*})
>> (morerocks => [marble sandstone granite chert pumice limestone])
>> > say @(%stash{*}).[0]
>> morerocks => [marble sandstone granite chert pumice limestone]
>> > say @(%stash{*}).[1]
>> Nil
>> > say @(%stash{*}).[0].{morerocks}
>> ===SORRY!=== Error while compiling:
>> Undeclared routine:
>> morerocks used at line 1
>> 
>> > say @(%stash{*}).[0].[0]
>> morerocks => [marble sandstone granite chert pumice limestone]
>> > say @(%stash{*}).[0].[1]
>> Index out of range. Is: 1, should be in 0..0
>>   in block  at  line 1
>> 
>> > say @(%stash{*}).[0].[0].perl
>> :morerocks(["marble", "sandstone", "granite", "chert", "pumice", 
>> "limestone"])
>> > say @(%stash{*}).[0].perl
>> :morerocks(["marble", "sandstone", "granite", "chert", "pumice", 
>> "limestone"])
>> 
>> 
>> I dunno.
>> 
>> From: William Michels via perl6-users > >
>> Sent: Thursday, March 12, 2020 5:44 PM
>> To: perl6-users mailto:perl6-users@perl.org>>
>> Cc: Joseph Brenner mailto:doom...@gmail.com>>; Timo 
>> Paulssen mailto:t...@wakelift.de>>; yary 
>> mailto:not@gmail.com>>
>> Subject: Re: stashing an array in a hash and yanking it back out
>>  
>> Thanks yary! The code you posted works perfectly.
>> 
>> Okay, one last question. I tried to use the 'DRY' principle to add
>> things to a hash. However, (thinking that a 'whatever star' might
>> reduce typing), I came up with an odd "ternary" structure. Can anyone
>> explain the last line of code, below?
>> 
>> mbook:~ homedir$ perl6
>> To exit type 'exit' or '^D'
>> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
>> [godzilla grendel wormface blob fingfangfoom tingler]

Re: stashing an array in a hash and yanking it back out

2020-03-15 Thread Andy Bach
>> really means something like
{* => (morerocks => [marble sandstone granite chert pumice limestone])}

> Taking into account that => has tighter precedence than , what you get in:
my %h = *, a => [1,2,3];

> is actually the following data structure:
%( Whatever => Pair )

That's sort of what I said, or, at least, saw.
> Regarding your use of postcircumfix [ ] on the data, you use it on Pair.

Not quite sure what this means, but is that how you'd get the [] 
array from %stash? I could get the pair back, but not the "inner" array of the 
pair's 2nd partner, so to speak:
>> say @(%stash{*})
(morerocks => [marble sandstone granite chert pumice limestone])
>> say @(%stash{*}).[0]
morerocks => [marble sandstone granite chert pumice limestone]
>> say @(%stash{*}).[1]
Nil
>> say @(%stash{*}).[0].{morerocks}
===SORRY!=== Error while compiling:
Undeclared routine:
morerocks used at line 1

>> say @(%stash{*}).[0].[0]
morerocks => [marble sandstone granite chert pumice limestone]


a


From: Vadim Belman 
Sent: Friday, March 13, 2020 12:50 PM
To: Andy Bach 
Cc: William Michels via perl6-users ; Joseph Brenner 
; Timo Paulssen ; yary 
Subject: Re: stashing an array in a hash and yanking it back out


There is no mystery whatsoever.

Consider the following:

my %h = "a", 1; # {a => 1}

Then consider this:

say *, *; # **


and also:

say *.VAR.WHAT; # (Whatever)

Taking into account that => has tighter precedence than , what you get in:

my %h = *, a => [1,2,3];

is actually the following data structure:

%( Whatever => Pair )

Regarding your use of postcircumfix [ ] on the data, you use it on Pair.

Best regards,
Vadim Belman

On Mar 13, 2020, at 11:52 AM, Andy Bach 
mailto:andy_b...@wiwb.uscourts.gov>> wrote:

> my  %stash = monsters => @monsters, rocks => @rocks
{monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
[marble sandstone granite chert pumice limestone]}
> my @more_rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = *, morerocks => @rocks
{* => morerocks => [marble sandstone granite chert pumice limestone]}
> say %stash{*}
(morerocks => [marble sandstone granite chert pumice limestone])

So, I'm guessing the display
{* => morerocks => [marble sandstone granite chert pumice limestone]}

really means something like
{* => (morerocks => [marble sandstone granite chert pumice limestone])}

maybe?
> say @(%stash{*})
(morerocks => [marble sandstone granite chert pumice limestone])
> say @(%stash{*}).[0]
morerocks => [marble sandstone granite chert pumice limestone]
> say @(%stash{*}).[1]
Nil
> say @(%stash{*}).[0].{morerocks}
===SORRY!=== Error while compiling:
Undeclared routine:
morerocks used at line 1

> say @(%stash{*}).[0].[0]
morerocks => [marble sandstone granite chert pumice limestone]
> say @(%stash{*}).[0].[1]
Index out of range. Is: 1, should be in 0..0
  in block  at  line 1

> say @(%stash{*}).[0].[0].perl
:morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"])
> say @(%stash{*}).[0].perl
:morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"])


I dunno.


From: William Michels via perl6-users 
mailto:perl6-users@perl.org>>
Sent: Thursday, March 12, 2020 5:44 PM
To: perl6-users mailto:perl6-users@perl.org>>
Cc: Joseph Brenner mailto:doom...@gmail.com>>; Timo Paulssen 
mailto:t...@wakelift.de>>; yary 
mailto:not@gmail.com>>
Subject: Re: stashing an array in a hash and yanking it back out

Thanks yary! The code you posted works perfectly.

Okay, one last question. I tried to use the 'DRY' principle to add
things to a hash. However, (thinking that a 'whatever star' might
reduce typing), I came up with an odd "ternary" structure. Can anyone
explain the last line of code, below?

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> my %stash = *, rocks => @rocks;
{* => rocks => [marble sandstone granite chert pumice limestone]}

Thanks, Bill.


On Wed, Mar 11, 2020 at 9:06 PM yary 
mailto:not@gmail.com>> wrote:
>
> The fat-arrow example makes sense, what this says
> %stash = rocks => @rocks
> is "replace %stash in its entirety with key rocks gets value @rocks"
> anything that used to be in %stash doesn't matter because this assignment 
> (left side) is the entirety of %stash
>
> what this says
> %stash{'rocks'} = @rocks
> is "replace the slot 'rocks' in %stash with @rocks"
> This assignment only is for the 'rocks' element of %stash so the other 
> elements remain unchanged.
>
> Extending the examples, first 3 lines are unchanged from 

Re: stashing an array in a hash and yanking it back out

2020-03-13 Thread Vadim Belman

There is no mystery whatsoever.

Consider the following:

my %h = "a", 1; # {a => 1}

Then consider this:

say *, *; # **


and also:

say *.VAR.WHAT; # (Whatever)

Taking into account that => has tighter precedence than , what you get in:

my %h = *, a => [1,2,3];

is actually the following data structure:

%( Whatever => Pair )

Regarding your use of postcircumfix [ ] on the data, you use it on Pair.

Best regards,
Vadim Belman

> On Mar 13, 2020, at 11:52 AM, Andy Bach  wrote:
> 
> > my  %stash = monsters => @monsters, rocks => @rocks
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
> [marble sandstone granite chert pumice limestone]}
> > my @more_rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
> > my  %stash = *, morerocks => @rocks
> {* => morerocks => [marble sandstone granite chert pumice limestone]}
> > say %stash{*}
> (morerocks => [marble sandstone granite chert pumice limestone])
> 
> So, I'm guessing the display
> {* => morerocks => [marble sandstone granite chert pumice limestone]}
> 
> really means something like
> {* => (morerocks => [marble sandstone granite chert pumice limestone])}
> 
> maybe?
> > say @(%stash{*})
> (morerocks => [marble sandstone granite chert pumice limestone])
> > say @(%stash{*}).[0]
> morerocks => [marble sandstone granite chert pumice limestone]
> > say @(%stash{*}).[1]
> Nil
> > say @(%stash{*}).[0].{morerocks}
> ===SORRY!=== Error while compiling:
> Undeclared routine:
> morerocks used at line 1
> 
> > say @(%stash{*}).[0].[0]
> morerocks => [marble sandstone granite chert pumice limestone]
> > say @(%stash{*}).[0].[1]
> Index out of range. Is: 1, should be in 0..0
>   in block  at  line 1
> 
> > say @(%stash{*}).[0].[0].perl
> :morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"])
> > say @(%stash{*}).[0].perl
> :morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"])
> 
> 
> I dunno.
> 
> From: William Michels via perl6-users  >
> Sent: Thursday, March 12, 2020 5:44 PM
> To: perl6-users mailto:perl6-users@perl.org>>
> Cc: Joseph Brenner mailto:doom...@gmail.com>>; Timo 
> Paulssen mailto:t...@wakelift.de>>; yary 
> mailto:not@gmail.com>>
> Subject: Re: stashing an array in a hash and yanking it back out
>  
> Thanks yary! The code you posted works perfectly.
> 
> Okay, one last question. I tried to use the 'DRY' principle to add
> things to a hash. However, (thinking that a 'whatever star' might
> reduce typing), I came up with an odd "ternary" structure. Can anyone
> explain the last line of code, below?
> 
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
> [godzilla grendel wormface blob fingfangfoom tingler]
> > my @rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
> > my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> > my %stash = *, rocks => @rocks;
> {* => rocks => [marble sandstone granite chert pumice limestone]}
> 
> Thanks, Bill.
> 
> 
> On Wed, Mar 11, 2020 at 9:06 PM yary  > wrote:
> >
> > The fat-arrow example makes sense, what this says
> > %stash = rocks => @rocks
> > is "replace %stash in its entirety with key rocks gets value @rocks"
> > anything that used to be in %stash doesn't matter because this assignment 
> > (left side) is the entirety of %stash
> >
> > what this says
> > %stash{'rocks'} = @rocks
> > is "replace the slot 'rocks' in %stash with @rocks"
> > This assignment only is for the 'rocks' element of %stash so the other 
> > elements remain unchanged.
> >
> > Extending the examples, first 3 lines are unchanged from before
> >
> > > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
> > [godzilla grendel wormface blob fingfangfoom tingler]
> > > my @rocks = << marble sandstone granite chert pumice limestone >>
> > [marble sandstone granite chert pumice limestone]
> > > my  %stash = monsters => @monsters
> > {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> >
> > > %stash = %stash, rocks => @rocks
> > {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks 
> > => [marble sandstone granite chert pumice limestone]}
> > > my %together = monsters => @monsters, rocks => @rocks
> > {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks 
> > => [marble sandstone granite chert pumice limestone]}
> >
> >
> > -y
> >
> >
> > On Tue, Mar 10, 2020 at 1:12 PM William Michels via perl6-users 
> > mailto:perl6-users@perl.org>> wrote:
> >>
> >> Hi Joe,
> >>
> >> So I had a chance to play with hashes further, and I noticed something
> >> that you might be interested in. It seems that 'bare' declaration of a
> >> hash with a "my" lexical scope enables you to stash away 

Re: stashing an array in a hash and yanking it back out

2020-03-13 Thread Andy Bach
> my  %stash = monsters => @monsters, rocks => @rocks
{monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
[marble sandstone granite chert pumice limestone]}
> my @more_rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = *, morerocks => @rocks
{* => morerocks => [marble sandstone granite chert pumice limestone]}
> say %stash{*}
(morerocks => [marble sandstone granite chert pumice limestone])

So, I'm guessing the display
{* => morerocks => [marble sandstone granite chert pumice limestone]}

really means something like
{* => (morerocks => [marble sandstone granite chert pumice limestone])}

maybe?
> say @(%stash{*})
(morerocks => [marble sandstone granite chert pumice limestone])
> say @(%stash{*}).[0]
morerocks => [marble sandstone granite chert pumice limestone]
> say @(%stash{*}).[1]
Nil
> say @(%stash{*}).[0].{morerocks}
===SORRY!=== Error while compiling:
Undeclared routine:
morerocks used at line 1

> say @(%stash{*}).[0].[0]
morerocks => [marble sandstone granite chert pumice limestone]
> say @(%stash{*}).[0].[1]
Index out of range. Is: 1, should be in 0..0
  in block  at  line 1

> say @(%stash{*}).[0].[0].perl
:morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"])
> say @(%stash{*}).[0].perl
:morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"])


I dunno.


From: William Michels via perl6-users 
Sent: Thursday, March 12, 2020 5:44 PM
To: perl6-users 
Cc: Joseph Brenner ; Timo Paulssen ; yary 

Subject: Re: stashing an array in a hash and yanking it back out

Thanks yary! The code you posted works perfectly.

Okay, one last question. I tried to use the 'DRY' principle to add
things to a hash. However, (thinking that a 'whatever star' might
reduce typing), I came up with an odd "ternary" structure. Can anyone
explain the last line of code, below?

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> my %stash = *, rocks => @rocks;
{* => rocks => [marble sandstone granite chert pumice limestone]}

Thanks, Bill.


On Wed, Mar 11, 2020 at 9:06 PM yary  wrote:
>
> The fat-arrow example makes sense, what this says
> %stash = rocks => @rocks
> is "replace %stash in its entirety with key rocks gets value @rocks"
> anything that used to be in %stash doesn't matter because this assignment 
> (left side) is the entirety of %stash
>
> what this says
> %stash{'rocks'} = @rocks
> is "replace the slot 'rocks' in %stash with @rocks"
> This assignment only is for the 'rocks' element of %stash so the other 
> elements remain unchanged.
>
> Extending the examples, first 3 lines are unchanged from before
>
> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
> [godzilla grendel wormface blob fingfangfoom tingler]
> > my @rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
> > my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>
> > %stash = %stash, rocks => @rocks
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
> [marble sandstone granite chert pumice limestone]}
> > my %together = monsters => @monsters, rocks => @rocks
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
> [marble sandstone granite chert pumice limestone]}
>
>
> -y
>
>
> On Tue, Mar 10, 2020 at 1:12 PM William Michels via perl6-users 
>  wrote:
>>
>> Hi Joe,
>>
>> So I had a chance to play with hashes further, and I noticed something
>> that you might be interested in. It seems that 'bare' declaration of a
>> hash with a "my" lexical scope enables you to stash away multiple
>> 'hash' elements at the top level using a 'curly brace' syntax. However
>> using the 'fat arrow' syntax will overwrite any previously stashed
>> 'top level' hash elements.
>>
>> Hopefully the REPL code below illustrates. First, 'curly brace' syntax:
>>
>> mbook:~ homedir$ perl6
>> To exit type 'exit' or '^D'
>> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
>> [godzilla grendel wormface blob fingfangfoom tingler]
>> > my @rocks = << marble sandstone granite chert pumice limestone >>
>> [marble sandstone granite chert pumice limestone]
>> > my %stash
>> {}
>> > %stash{'monsters'} = @monsters
>> [godzilla grendel wormface blob fingfangfoom tingler]
>> > say %stash
>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>> > %stash{'rocks'} = @rocks
>> [marble sandstone granite chert pumice limestone]
>> > say 

Re: stashing an array in a hash and yanking it back out

2020-03-12 Thread William Michels via perl6-users
Thanks yary! The code you posted works perfectly.

Okay, one last question. I tried to use the 'DRY' principle to add
things to a hash. However, (thinking that a 'whatever star' might
reduce typing), I came up with an odd "ternary" structure. Can anyone
explain the last line of code, below?

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> my %stash = *, rocks => @rocks;
{* => rocks => [marble sandstone granite chert pumice limestone]}

Thanks, Bill.


On Wed, Mar 11, 2020 at 9:06 PM yary  wrote:
>
> The fat-arrow example makes sense, what this says
> %stash = rocks => @rocks
> is "replace %stash in its entirety with key rocks gets value @rocks"
> anything that used to be in %stash doesn't matter because this assignment 
> (left side) is the entirety of %stash
>
> what this says
> %stash{'rocks'} = @rocks
> is "replace the slot 'rocks' in %stash with @rocks"
> This assignment only is for the 'rocks' element of %stash so the other 
> elements remain unchanged.
>
> Extending the examples, first 3 lines are unchanged from before
>
> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
> [godzilla grendel wormface blob fingfangfoom tingler]
> > my @rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
> > my  %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>
> > %stash = %stash, rocks => @rocks
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
> [marble sandstone granite chert pumice limestone]}
> > my %together = monsters => @monsters, rocks => @rocks
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks => 
> [marble sandstone granite chert pumice limestone]}
>
>
> -y
>
>
> On Tue, Mar 10, 2020 at 1:12 PM William Michels via perl6-users 
>  wrote:
>>
>> Hi Joe,
>>
>> So I had a chance to play with hashes further, and I noticed something
>> that you might be interested in. It seems that 'bare' declaration of a
>> hash with a "my" lexical scope enables you to stash away multiple
>> 'hash' elements at the top level using a 'curly brace' syntax. However
>> using the 'fat arrow' syntax will overwrite any previously stashed
>> 'top level' hash elements.
>>
>> Hopefully the REPL code below illustrates. First, 'curly brace' syntax:
>>
>> mbook:~ homedir$ perl6
>> To exit type 'exit' or '^D'
>> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
>> [godzilla grendel wormface blob fingfangfoom tingler]
>> > my @rocks = << marble sandstone granite chert pumice limestone >>
>> [marble sandstone granite chert pumice limestone]
>> > my %stash
>> {}
>> > %stash{'monsters'} = @monsters
>> [godzilla grendel wormface blob fingfangfoom tingler]
>> > say %stash
>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>> > %stash{'rocks'} = @rocks
>> [marble sandstone granite chert pumice limestone]
>> > say %stash
>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler],
>> rocks => [marble sandstone granite chert pumice limestone]}
>> > exit
>> mbook:~ homedir$
>>
>> [and now try 'fat arrow' syntax]
>>
>> mbook:~ homedir$ perl6
>> To exit type 'exit' or '^D'
>> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
>> [godzilla grendel wormface blob fingfangfoom tingler]
>> > my @rocks = << marble sandstone granite chert pumice limestone >>
>> [marble sandstone granite chert pumice limestone]
>> > my %stash
>> {}
>> > %stash = monsters => @monsters
>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>> > %stash = rocks => @rocks
>> {rocks => [marble sandstone granite chert pumice limestone]}
>> > say %stash
>> {rocks => [marble sandstone granite chert pumice limestone]}
>> > say %stash
>> (Any)
>> > exit
>> mbook:~ homedir$ perl6 -v
>> This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
>> implementing Perl 6.d.
>>
>> HTH, Bill.
>>
>>
>>
>> On Thu, Mar 5, 2020 at 6:10 PM Joseph Brenner  wrote:
>> >
>> > William Michels  wrote:
>> >
>> > > Yes, since I was working in the REPL, I tried compacting Joe's code by
>> > > eliminating the "my %stash" line at the top, and adding "my" to the third
>> > > line.
>> >
>> > I noticed the additional "my" in there, but I wouldn't have been able
>> > to tell you why it was behaving like it was...
>> >
>> > On the plus side, I see that if you tried to do that in a script, it
>> > would warn you:
>> >
>> > Potential difficulties:
>> >Redeclaration of symbol '%stash'


Re: stashing an array in a hash and yanking it back out

2020-03-11 Thread yary
The fat-arrow example makes sense, what this says
%stash = rocks => @rocks
is "replace %stash in its entirety with key rocks gets value @rocks"
anything that used to be in %stash doesn't matter because this assignment
(left side) is the entirety of %stash

what this says
%stash{'rocks'} = @rocks
is "replace the slot 'rocks' in %stash with @rocks"
This assignment only is for the 'rocks' element of %stash so the other
elements remain unchanged.

Extending the examples, first 3 lines are unchanged from before

> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my  %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}

>* %stash = %stash, rocks => @rocks*
{monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks
=> [marble sandstone granite chert pumice limestone]}
> *my %together = monsters => @monsters, rocks => @rocks*
{monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks
=> [marble sandstone granite chert pumice limestone]}


-y


On Tue, Mar 10, 2020 at 1:12 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Hi Joe,
>
> So I had a chance to play with hashes further, and I noticed something
> that you might be interested in. It seems that 'bare' declaration of a
> hash with a "my" lexical scope enables you to stash away multiple
> 'hash' elements at the top level using a 'curly brace' syntax. However
> using the 'fat arrow' syntax will overwrite any previously stashed
> 'top level' hash elements.
>
> Hopefully the REPL code below illustrates. First, 'curly brace' syntax:
>
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
> [godzilla grendel wormface blob fingfangfoom tingler]
> > my @rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
> > my %stash
> {}
> > %stash{'monsters'} = @monsters
> [godzilla grendel wormface blob fingfangfoom tingler]
> > say %stash
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> > %stash{'rocks'} = @rocks
> [marble sandstone granite chert pumice limestone]
> > say %stash
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler],
> rocks => [marble sandstone granite chert pumice limestone]}
> > exit
> mbook:~ homedir$
>
> [and now try 'fat arrow' syntax]
>
> mbook:~ homedir$ perl6
> To exit type 'exit' or '^D'
> > my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
> [godzilla grendel wormface blob fingfangfoom tingler]
> > my @rocks = << marble sandstone granite chert pumice limestone >>
> [marble sandstone granite chert pumice limestone]
> > my %stash
> {}
> > %stash = monsters => @monsters
> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> > %stash = rocks => @rocks
> {rocks => [marble sandstone granite chert pumice limestone]}
> > say %stash
> {rocks => [marble sandstone granite chert pumice limestone]}
> > say %stash
> (Any)
> > exit
> mbook:~ homedir$ perl6 -v
> This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
> implementing Perl 6.d.
>
> HTH, Bill.
>
>
>
> On Thu, Mar 5, 2020 at 6:10 PM Joseph Brenner  wrote:
> >
> > William Michels  wrote:
> >
> > > Yes, since I was working in the REPL, I tried compacting Joe's code by
> > > eliminating the "my %stash" line at the top, and adding "my" to the
> third
> > > line.
> >
> > I noticed the additional "my" in there, but I wouldn't have been able
> > to tell you why it was behaving like it was...
> >
> > On the plus side, I see that if you tried to do that in a script, it
> > would warn you:
> >
> > Potential difficulties:
> >Redeclaration of symbol '%stash'
>


Re: stashing an array in a hash and yanking it back out

2020-03-10 Thread William Michels via perl6-users
Hi Joe,

So I had a chance to play with hashes further, and I noticed something
that you might be interested in. It seems that 'bare' declaration of a
hash with a "my" lexical scope enables you to stash away multiple
'hash' elements at the top level using a 'curly brace' syntax. However
using the 'fat arrow' syntax will overwrite any previously stashed
'top level' hash elements.

Hopefully the REPL code below illustrates. First, 'curly brace' syntax:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my %stash
{}
> %stash{'monsters'} = @monsters
[godzilla grendel wormface blob fingfangfoom tingler]
> say %stash
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> %stash{'rocks'} = @rocks
[marble sandstone granite chert pumice limestone]
> say %stash
{monsters => [godzilla grendel wormface blob fingfangfoom tingler],
rocks => [marble sandstone granite chert pumice limestone]}
> exit
mbook:~ homedir$

[and now try 'fat arrow' syntax]

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my %stash
{}
> %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> %stash = rocks => @rocks
{rocks => [marble sandstone granite chert pumice limestone]}
> say %stash
{rocks => [marble sandstone granite chert pumice limestone]}
> say %stash
(Any)
> exit
mbook:~ homedir$ perl6 -v
This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
implementing Perl 6.d.

HTH, Bill.



On Thu, Mar 5, 2020 at 6:10 PM Joseph Brenner  wrote:
>
> William Michels  wrote:
>
> > Yes, since I was working in the REPL, I tried compacting Joe's code by
> > eliminating the "my %stash" line at the top, and adding "my" to the third
> > line.
>
> I noticed the additional "my" in there, but I wouldn't have been able
> to tell you why it was behaving like it was...
>
> On the plus side, I see that if you tried to do that in a script, it
> would warn you:
>
> Potential difficulties:
>Redeclaration of symbol '%stash'


Re: stashing an array in a hash and yanking it back out

2020-03-05 Thread Joseph Brenner
William Michels  wrote:

> Yes, since I was working in the REPL, I tried compacting Joe's code by
> eliminating the "my %stash" line at the top, and adding "my" to the third
> line.

I noticed the additional "my" in there, but I wouldn't have been able
to tell you why it was behaving like it was...

On the plus side, I see that if you tried to do that in a script, it
would warn you:

Potential difficulties:
   Redeclaration of symbol '%stash'


Re: stashing an array in a hash and yanking it back out

2020-03-05 Thread Joseph Brenner
 Timo Paulssen  wrote:

>  The reason for that is that `my %foo{Bar}` is syntax for restricting
>  the keys of the hash to a specific type (by default it's `Str(Any)`)

Hm.. That's certainly useful, I hadn't even gotten to wondering how to
do that yet.

> and giving a string instance ("monsters" in this case) just takes the type of 
> the value.

That seems a little peculiar, I have to say.  Using an instance as a type...


Re: stashing an array in a hash and yanking it back out

2020-03-05 Thread William Michels via perl6-users
Hi Timo and thank you for the note.

Yes, since I was working in the REPL, I tried compacting Joe's code by
eliminating the "my %stash" line at the top, and adding "my" to the third
line.
I figured since Joe's code looked like a closure (curly brackets and all),
it wouldn't be an issue.
But the two runs through the REPL below give wildly different results:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my %stash
{}
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> %stash{'monsters'} = @monsters;
[godzilla grendel wormface blob fingfangfoom tingler]
>
> exit
mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my %stash{'monsters'} = @monsters;
{fingfangfoom => tingler, godzilla => grendel, wormface => blob}
>

>From Liz's note it seems to me the correct way to do this is:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
>
> .say for %stash;
[godzilla grendel wormface blob fingfangfoom tingler]
> %stash.say
[godzilla grendel wormface blob fingfangfoom tingler]
>

Thanks again, Bill.




On Thu, Mar 5, 2020 at 12:33 AM Timo Paulssen  wrote:

>
> Hi William,
>
> The line that has the important difference is where you put a `my` in
> front of `%stash{'monsters'} = @monsters`. Probably a copy-paste error or
> something like that.
>
> >> my %stash > {} >> my @monsters = < fingfangfoom >> tingler >> > [godzilla grendel wormface blob fingfangfoom
> tingler] >> my %stash{'monsters'} = @monsters; > {fingfangfoom =>
> tingler, godzilla => grendel, wormface => blob} >> my @m =
> %stash{'monsters'}; > [(Any)] >> say @m > [(Any)] >> exit
>
> timo@schmand ~> perl6 -e 'my %stash{"monsters"} = :1a; dd %stash'
> Hash[Any,Str] %stash = (my Any %{Str} = :a(1))
> timo@schmand ~> perl6 -e 'my %stash; %stash{"monsters"} = :1a; dd %stash'
> Hash %stash = {:monsters(:a(1))}
>
> Here you can see that in the case of having a "my" in front, the assigned
> data doesn't get put in the hash at the "monsters" key. instead, it gets
> assigned to the whole hash. The reason for that is that `my %foo{Bar}` is
> syntax for restricting the keys of the hash to a specific type (by default
> it's `Str(Any)`) and giving a string instance ("monsters" in this case)
> just takes the type of the value.
>
> Hope that clears things up
>   - Timo
>


Re: stashing an array in a hash and yanking it back out

2020-03-05 Thread Timo Paulssen

Hi William,

The line that has the important difference is where you put a `my` in
front of `%stash{'monsters'} = @monsters`. Probably a copy-paste error
or something like that.

>> my %stash> {}>> my @monsters = <> fingfangfoom>>
tingler>>> [godzilla grendel wormface blob fingfangfoom tingler]>> my
%stash{'monsters'} = @monsters;> {fingfangfoom => tingler, godzilla =>
grendel, wormface => blob}>> my @m = %stash{'monsters'};> [(Any)]>> say
@m> [(Any)]>> exit

timo@schmand ~> perl6 -e 'my %stash{"monsters"} = :1a; dd %stash'
Hash[Any,Str] %stash = (my Any %{Str} = :a(1))
timo@schmand ~> perl6 -e 'my %stash; %stash{"monsters"} = :1a; dd %stash'
Hash %stash = {:monsters(:a(1))}

Here you can see that in the case of having a "my" in front, the
assigned data doesn't get put in the hash at the "monsters" key.
instead, it gets assigned to the whole hash. The reason for that is that
`my %foo{Bar}` is syntax for restricting the keys of the hash to a
specific type (by default it's `Str(Any)`) and giving a string instance
("monsters" in this case) just takes the type of the value.

Hope that clears things up
  - Timo



Re: stashing an array in a hash and yanking it back out

2020-03-05 Thread William Michels via perl6-users
Hi Joe, I tested the code you put up using the REPL, and I have to
start off by saying that I was unable to reproduce your results,
specifically where you creat the "@m" array. This could be a
REPL-specific issue, or a version-specific issue (mine is 2019.07.1
Perl 6.d):

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my %stash
{}
> my @monsters = <>
[godzilla grendel wormface blob fingfangfoom tingler]
> my %stash{'monsters'} = @monsters;
{fingfangfoom => tingler, godzilla => grendel, wormface => blob}
> my @m = %stash{'monsters'};
[(Any)]
> say @m
[(Any)]
> exit

The first thing I notice is when you create a hash from an array using
your method, you pair together 'monsters' from your array. Is this
what you want? Below I show creating a 0-to-5 indexed %stash (hash)
object simply by assigning @monsters.pairs to it. You can back-out
again to an "@-sigilled" variable (see "@monsters_redux" example).
[Note, somewhat surprisingly if you call .WHAT on %stash.values, you
find that it is actually a ".Seq"].

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = <>
[godzilla grendel wormface blob fingfangfoom tingler]
> my %stash = @monsters.pairs
{0 => godzilla, 1 => grendel, 2 => wormface, 3 => blob, 4 =>
fingfangfoom, 5 => tingler}
> say %stash.WHAT
(Hash)
> say %stash.values.WHAT
(Seq)
> my @monsters_redux = %stash.values
[godzilla fingfangfoom grendel wormface blob tingler]
> say @monsters_redux.WHAT
(Array)
>

I feel that an advantage of working with hashes/arrays in Raku/Perl6
is they mesh very gracefully, especially using .pairs and .kv methods.
I had occasion to take some duplicate values and count up occurrences:
I simply called the ".Bag" method on an array. I didn't need to go so
far as create a hash, but I could have done so easily. See below for
some ideas, and note the two examples at the end, which differ only in
order:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters2 = < tingler>>
[mothra mothra godzilla grendel wormface blob fingfangfoom tingler]
> say @monsters2.Bag.pairs.sort(*.values).reverse
(mothra => 2 tingler => 1 blob => 1 godzilla => 1 fingfangfoom => 1
wormface => 1 grendel => 1)
> my %stash2 =  @monsters2.Bag.pairs
{blob => 1, fingfangfoom => 1, godzilla => 1, grendel => 1, mothra =>
2, tingler => 1, wormface => 1}
> for @monsters2.Bag.pairs.kv {.perl.say}
0
:tingler(1)
1
:mothra(2)
2
:blob(1)
3
:fingfangfoom(1)
4
:godzilla(1)
5
:grendel(1)
6
:wormface(1)
> for %stash2.Bag.pairs.kv {.perl.say}
0
:godzilla(1)
1
:fingfangfoom(1)
2
:grendel(1)
3
:wormface(1)
4
:tingler(1)
5
:mothra(2)
6
:blob(1)
>

HTH, Bill.











On Wed, Mar 4, 2020 at 7:36 PM Joseph Brenner  wrote:
>
> There might not be much to say about this, I just though I'd
> mention that I keep getting re-surprised by basics with Raku,
> like this one, where first I stash an array away in a hash and
> later try to pull the array out again:
>
> my %stash;
> my @monsters =
>   << godzilla grendel wormface blob fingfangfoom tingler >>;
> %stash{'monsters'} = @monsters;
>
> Now some time later, when I wanted to extract that array again,
> my first thought was to do this:
>
> my @m = %stash{'monsters'};
>
> But that doesn't get the original array back, instead you end up
> with the entire original array as the first element of a newly
> created array:
>
> # [[godzilla grendel wormface blob fingfangfoom tingler]]
>
> Yary Hluchan pointed out that I could slip it out, and get what
> I wanted:
>
> my @m = | %stash{'monsters'};
> say @m;
> # [godzilla grendel wormface blob fingfangfoom tingler]
>
> Though for what I'm doing now, I think it might be better to
> just alias it with the binding operator:
>
>my @m := %stash{'monsters'};
>
> So, like I said: I don't have any particular questions about this,
> I think I more or less know what's going on... it will be a while
> before I stop tripping over this sort of thing, though.


Re: stashing an array in a hash and yanking it back out

2020-03-04 Thread Elizabeth Mattijsen
FWIW, it's the same as if you would do:

my @a = ^10;
my $b = @a;
dd $b;  # Array $b = $[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

A scalar can only hold a single value.  That single value in $b is an Array.  
But it is still a single value (shown in the output by the $[ ] construct.  
Adding .list of circumfixing it with @( ) makes it a "real" iterable thing 
again:

dd $b.list;  # Array @a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
dd @($b);# Array @a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

With regards to slipping, you can actually do this when assigning to the hash 
already, which is handy if you need to iterate more than once over the value 
for that key:

my @a = ^10;
my %h = a => @a;
.say for %h;
[0 1 2 3 4 5 6 7 8 9]

my @a = ^10;
my %h = a => |@a;
.say for %h;
0
1
2
etc.

> On 5 Mar 2020, at 04:36, Joseph Brenner  wrote:
> 
> There might not be much to say about this, I just though I'd
> mention that I keep getting re-surprised by basics with Raku,
> like this one, where first I stash an array away in a hash and
> later try to pull the array out again:
> 
>my %stash;
>my @monsters =
>  << godzilla grendel wormface blob fingfangfoom tingler >>;
>%stash{'monsters'} = @monsters;
> 
> Now some time later, when I wanted to extract that array again,
> my first thought was to do this:
> 
>my @m = %stash{'monsters'};
> 
> But that doesn't get the original array back, instead you end up
> with the entire original array as the first element of a newly
> created array:
> 
># [[godzilla grendel wormface blob fingfangfoom tingler]]
> 
> Yary Hluchan pointed out that I could slip it out, and get what
> I wanted:
> 
>my @m = | %stash{'monsters'};
>say @m;
># [godzilla grendel wormface blob fingfangfoom tingler]
> 
> Though for what I'm doing now, I think it might be better to
> just alias it with the binding operator:
> 
>   my @m := %stash{'monsters'};
> 
> So, like I said: I don't have any particular questions about this,
> I think I more or less know what's going on... it will be a while
> before I stop tripping over this sort of thing, though.


stashing an array in a hash and yanking it back out

2020-03-04 Thread Joseph Brenner
There might not be much to say about this, I just though I'd
mention that I keep getting re-surprised by basics with Raku,
like this one, where first I stash an array away in a hash and
later try to pull the array out again:

my %stash;
my @monsters =
  << godzilla grendel wormface blob fingfangfoom tingler >>;
%stash{'monsters'} = @monsters;

Now some time later, when I wanted to extract that array again,
my first thought was to do this:

my @m = %stash{'monsters'};

But that doesn't get the original array back, instead you end up
with the entire original array as the first element of a newly
created array:

# [[godzilla grendel wormface blob fingfangfoom tingler]]

Yary Hluchan pointed out that I could slip it out, and get what
I wanted:

my @m = | %stash{'monsters'};
say @m;
# [godzilla grendel wormface blob fingfangfoom tingler]

Though for what I'm doing now, I think it might be better to
just alias it with the binding operator:

   my @m := %stash{'monsters'};

So, like I said: I don't have any particular questions about this,
I think I more or less know what's going on... it will be a while
before I stop tripping over this sort of thing, though.