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-

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] > %stas

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 bl

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 cumbersom

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

2020-03-17 Thread Joseph Brenner
zilla 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 > &g

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

2020-03-17 Thread Joseph Brenner
t;>>>> > my %stash = monsters => @monsters >>>>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler]} >>>>> > %stash.append: (rocks => @rocks); >>>>> {monsters => [godzilla grendel wormface blob fingfangfoom ti

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
#x27;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

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

2020-03-17 Thread Vadim Belman
rendel wormface blob fingfangfoom tingler]} >>>> > %stash.append: (rocks => @rocks); >>>> {monsters => [godzilla grendel wormface blob fingfangfoom tingler], rocks >>>> => [marble sandstone granite chert pumice limestone]} >>>> > Though I'

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

2020-03-16 Thread Andy Bach
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

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

2020-03-15 Thread Vadim Belman
ne 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 &

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

2020-03-15 Thread Andy Bach
ach 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.W

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

2020-03-13 Thread Vadim Belman
uot;granite", "chert", "pumice", "limestone"]) > > say @(%stash{*}).[0].perl > :morerocks(["marble", "sandstone", "granite", "chert", "pumice", "limestone"]) > > > I dunno. > > From: Will

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

2020-03-13 Thread Andy Bach
[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: Josep

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:

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

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 '

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...

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

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

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]>>

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

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 .lis

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