From:

Date:

July 14, 2021 18:55Subject:

Re: [naive] hash assingmentMessage ID:

CADaz7Gk8XZaYW9XYdD9N8hbZERvXQ6yJ71hhqyuEmy0pQPExLA@mail.gmail.comUnfortunately, given this: my %a = 'column1' => [1...5], 'column2' => ['a'...'e'] > column1 and column2 cannot yet be referenced to create column3. You need to do that on another line: %a<column3> = %a<column1>.map: { .sqrt }; Which gives the following: > %a.gist.say # {column1 => [1 2 3 4 5], column2 => [a b c d e], column3 => (1 1.4142135623730951 1.7320508075688772 2 2.23606797749979)} Does this help? - X On Wed, Jul 14, 2021 at 2:32 PM Aureliano Guedes <guedes.aureliano@gmail.com> wrote: > 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 <mt1957@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 >Thread Previous | Thread Next

- [naive] hash assingment by Aureliano Guedes
- Re: [naive] hash assingment by Marcel Timmerman
- Re: [naive] hash assingment by Aureliano Guedes
- Re: [naive] hash assingment by Daniel Sockwell
- Re: [naive] hash assingment by Patrick R. Michaud
- Re: [naive] hash assingment by Aureliano Guedes
- Re: [naive] hash assingment by Brad Gilbert
- Re: [naive] hash assingment by Vadim Belman
- Re: [naive] hash assingment by William Michels via perl6-users
**Re: [naive] hash assingment**by Clifton Wood- Re: [naive] hash assingment by Aureliano Guedes
- Re: [naive] hash assingment by JJ Merelo

nntp.perl.org: Perl Programming lists via nntp and http.

Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About