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