El mié, 14 jul 2021 a las 19:43, Aureliano Guedes (<
guedes.aureli...@gmail.com>) escribió:

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

This is not going to be faster in the general case, only when the
operations done at every step take enough time, and the array is big
enough. In the general case, this might be even slower. Also, it's lower
case hyper, and it must go before the operation to be "hypered", like map.


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

Yep, you can just write:
my %a = 'column1' => [1...5], 'column2' => ['a'...'e']

Raku knows it's a hash, it can figure out the two Pairs go there.

>
> 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']⏏}
>
> Now we got an error.
>

:= is for variable binding; you could do something like

my %a := {'column1' => [1...5], 'column2' => ['a'...'e']}

Which will bind lhs to rhs, saying: yes, I know that's a hash, that's
exactly what I want. No warning then. That's where you had to use binding.


> Someone may explain me why I got this error??
>

Hope that helps. You might want to have a look at the documentation, too:
https://docs.raku.org/routine/:=

Cheers

JJ

Reply via email to