Thanks JJ, Marcel, Matthew

That's help me a lot to understand how Raku hashes work;
Little bit complex compared to Perl5.

But now I got another question

given
my %a = 'column1' => [1...5], 'column2' => ['a'...'e']

I want to calculate sqrt and store in column3
> %a{'column1'}.map({ .sqrt })
(1 1.4142135623730951 1.7320508075688772 2 2.23606797749979)
> %a{'column3'} = %a{'column1'}.map({ .sqrt })
> %a{'column3'}
(1 1.4142135623730951 1.7320508075688772 2 2.23606797749979)
> %a.keys
(column1 column3 column2)

But...
> %a{'column1'} ==> map( { .sqrt } )
(2.23606797749979)

How I access the array's values within the hash?


On Wed, Jul 14, 2021 at 2:55 PM Marcel Timmerman <mt1...@gmail.com> wrote:

> On 7/14/21 7:43 PM, Aureliano Guedes wrote:
>
> Hi all,
>
> Trying to knowing a little bit more about Raku lang, I decided to write a
> simple (as possible) lib to became similar to R/dplyr or Python/Pandas
> method to data wrangle.
>
> So, Raku gives us the possibility to deal with data in a functional way,
> given the native pipe operator, which is wonderful for newbies.
> > @a = 1..100
> > @a ==> map( { .sqrt } )
> > @a ==> HYPER( { .sqrt } ) # faster map
> Even it is being *too verbose*, is good enough for the first moment to a
> data scientist.
>
> So I'm trying to decide the best way to abstract columns.
> First, I decide to use a hash where the key is the column name and the
> value is the oriented list ou array.
>
> > my %a = {'column1' => [1...5], 'column2' => ['a'...'e']}
> Potential difficulties:
>     Useless use of hash composer on right side of hash assignment; did you
> mean := instead?
>     at line 2
>     ------> <BOL>⏏<EOL>
> {column1 => [1 2 3 4 5], column2 => [a b c d e]}
>
> It is a warning, not an error!
>
> But let's obey the warning.
> > my %a = {'column1' := [1...5], 'column2' := ['a'...'e']}
> ===SORRY!=== Error while compiling:
> Cannot use bind operator with this left-hand side
> ------> n1' := [1...5], 'column2' := ['a'...'e']⏏}
>
>
> ':=' in the error is meant to replace the assignment so you are binding
> directly to the hash.
> So write,
>
> my %a := {'column1' => [1...5], 'column2' => ['a'...'e']}
>
> Without the binding you could write instead
>
> my %a = 'column1' => [1...5], 'column2' => ['a'...'e']
>
> See also https://docs.raku.org/type/Hash and
> https://docs.raku.org/routine/:=
>
>
> Now we got an error.
>
> Someone may explain me why I got this error??
>
> Thanks in advance
>
>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>
>
>

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

Reply via email to