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: perl6 vs ruby

2020-03-05 Thread Brad Gilbert
There isn't currently a way to compile to a single file, but there was a
GSOC project that started on it.

On Thu, Mar 5, 2020, 7:17 AM Aureliano Guedes 
wrote:

> I have another question for you. Maybe it must be better done in another
> thread...
> But, there is a way to compile Raku code in a binary capable to run in a
> system without a Raku installation?
>
> On Thu, Mar 5, 2020 at 6:17 AM Elizabeth Mattijsen  wrote:
>
>> Well, internally many parts still have Perl 6 in them.  Renaming those
>> is...  an interesting task.
>>
>> Online, most resources have been renamed, but some still need to be
>> done.  This mailing list being one of them.  Unfortunately, it is part of
>> the crumbling Perl infrastructure, so it's unclear what would be the best
>> course forward on this.
>>
>> > On 5 Mar 2020, at 10:09, Wyatt Chun  wrote:
>> >
>> > Hi
>> >
>> > Is perl6 totall renamed to raku?
>> >
>> > regards
>> >
>> > On Wed, Mar 4, 2020 at 4:15 AM Fields, Christopher J <
>> cjfie...@illinois.edu> wrote:
>> > A few people had started a port of some BioPerl code to Perl6 a while
>> ago; I tested this recently and it still passed tests.
>> >
>> > https://github.com/cjfields/bioperl6
>> >
>> > It should be renamed to bioraku!
>> >
>> > Chris
>> >
>> > Sent from my iPhone
>> >
>> >> On Mar 3, 2020, at 11:41 AM, Parrot Raiser <1parr...@gmail.com> wrote:
>> >>
>> >> 
>> >>> we use ruby for Biological data analysis. I wish perl6 should have
>> got that capability.
>> >>
>> >> Would you like to give us a sample problem,, to see if someone can
>> >> show a potential solution?
>>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


Re: perl6 vs ruby

2020-03-05 Thread Aureliano Guedes
I have another question for you. Maybe it must be better done in another
thread...
But, there is a way to compile Raku code in a binary capable to run in a
system without a Raku installation?

On Thu, Mar 5, 2020 at 6:17 AM Elizabeth Mattijsen  wrote:

> Well, internally many parts still have Perl 6 in them.  Renaming those
> is...  an interesting task.
>
> Online, most resources have been renamed, but some still need to be done.
> This mailing list being one of them.  Unfortunately, it is part of the
> crumbling Perl infrastructure, so it's unclear what would be the best
> course forward on this.
>
> > On 5 Mar 2020, at 10:09, Wyatt Chun  wrote:
> >
> > Hi
> >
> > Is perl6 totall renamed to raku?
> >
> > regards
> >
> > On Wed, Mar 4, 2020 at 4:15 AM Fields, Christopher J <
> cjfie...@illinois.edu> wrote:
> > A few people had started a port of some BioPerl code to Perl6 a while
> ago; I tested this recently and it still passed tests.
> >
> > https://github.com/cjfields/bioperl6
> >
> > It should be renamed to bioraku!
> >
> > Chris
> >
> > Sent from my iPhone
> >
> >> On Mar 3, 2020, at 11:41 AM, Parrot Raiser <1parr...@gmail.com> wrote:
> >>
> >> 
> >>> we use ruby for Biological data analysis. I wish perl6 should have got
> that capability.
> >>
> >> Would you like to give us a sample problem,, to see if someone can
> >> show a potential solution?
>


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


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: perl6 vs ruby

2020-03-05 Thread Elizabeth Mattijsen
Well, internally many parts still have Perl 6 in them.  Renaming those is...  
an interesting task.

Online, most resources have been renamed, but some still need to be done.  This 
mailing list being one of them.  Unfortunately, it is part of the crumbling 
Perl infrastructure, so it's unclear what would be the best course forward on 
this. 

> On 5 Mar 2020, at 10:09, Wyatt Chun  wrote:
> 
> Hi
> 
> Is perl6 totall renamed to raku?
> 
> regards
> 
> On Wed, Mar 4, 2020 at 4:15 AM Fields, Christopher J  
> wrote:
> A few people had started a port of some BioPerl code to Perl6 a while ago; I 
> tested this recently and it still passed tests.  
> 
> https://github.com/cjfields/bioperl6
> 
> It should be renamed to bioraku!
> 
> Chris
> 
> Sent from my iPhone
> 
>> On Mar 3, 2020, at 11:41 AM, Parrot Raiser <1parr...@gmail.com> wrote:
>> 
>> 
>>> we use ruby for Biological data analysis. I wish perl6 should have got that 
>>> capability.
>> 
>> Would you like to give us a sample problem,, to see if someone can
>> show a potential solution?


Re: perl6 vs ruby

2020-03-05 Thread Wyatt Chun
Hi

Is perl6 totall renamed to raku?

regards

On Wed, Mar 4, 2020 at 4:15 AM Fields, Christopher J 
wrote:

> A few people had started a port of some BioPerl code to Perl6 a while ago;
> I tested this recently and it still passed tests.
>
> https://github.com/cjfields/bioperl6
>
> It should be renamed to bioraku!
>
> Chris
>
> Sent from my iPhone
>
> On Mar 3, 2020, at 11:41 AM, Parrot Raiser <1parr...@gmail.com> wrote:
>
> 
>
> we use ruby for Biological data analysis. I wish perl6 should have got
> that capability.
>
>
> Would you like to give us a sample problem,, to see if someone can
> show a potential solution?
>
>


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.