Re: Baby steps to create a dataframe structure

2020-07-22 Thread Tessa Plum

Marc Chantreux wrote:

But the idea is to implement cooperatively those tools

if you do that, i'll be a very suportive user (and casual contributor
if i can).


me second. :)

Regards.


Re: Baby steps to create a dataframe structure

2020-07-22 Thread JJ Merelo
The Raku wrapper for GSL is ready, specifically all matrix operations,
check it out. It's extremely fast, and could be the foundation for these
data frames.

El mié., 22 jul. 2020 a las 9:15, Tessa Plum () escribió:

> Marc Chantreux wrote:
> >> But the idea is to implement cooperatively those tools
> > if you do that, i'll be a very suportive user (and casual contributor
> > if i can).
>
> me second. :)
>
> Regards.
>


-- 
JJ


Re: Baby steps to create a dataframe structure

2020-07-22 Thread Tom Browder
On Wed, Jul 22, 2020 at 06:51 JJ Merelo  wrote:

> The Raku wrapper for GSL is ready, specifically all matrix operations,
> check it out. It's extremely fast, and could be the foundation for these
> data frames.
>

Depending on your use of the GSL, as I recall the license restricts
commercial use.

Best regards,

-Tom


Re: Baby steps to create a dataframe structure

2020-07-22 Thread JJ Merelo
Well, you can use it for commercial software as long as you distribute the
source with it...

El mié., 22 jul. 2020 a las 14:07, Fernando Santagata (<
nando.santag...@gmail.com>) escribió:

> Here https://www.gnu.org/software/gsl/ I see this note:
>
> The bottom line for commercial users:
>> GSL can be used internally ("in-house") without restriction, but only
>> redistributed in other software that is under the GNU GPL.
>>
>
> So yes, the license restricts the use to GNU GPL software; no other
> restriction that I noticed.
>
> On Wed, Jul 22, 2020 at 2:03 PM Tom Browder  wrote:
>
>> On Wed, Jul 22, 2020 at 06:51 JJ Merelo  wrote:
>>
>>> The Raku wrapper for GSL is ready, specifically all matrix operations,
>>> check it out. It's extremely fast, and could be the foundation for these
>>> data frames.
>>>
>>
>> Depending on your use of the GSL, as I recall the license restricts
>> commercial use.
>>
>> Best regards,
>>
>> -Tom
>>
>
>
> --
> Fernando Santagata
>


-- 
JJ


Re: Baby steps to create a dataframe structure

2020-07-22 Thread Fernando Santagata
Here https://www.gnu.org/software/gsl/ I see this note:

The bottom line for commercial users:
> GSL can be used internally ("in-house") without restriction, but only
> redistributed in other software that is under the GNU GPL.
>

So yes, the license restricts the use to GNU GPL software; no other
restriction that I noticed.

On Wed, Jul 22, 2020 at 2:03 PM Tom Browder  wrote:

> On Wed, Jul 22, 2020 at 06:51 JJ Merelo  wrote:
>
>> The Raku wrapper for GSL is ready, specifically all matrix operations,
>> check it out. It's extremely fast, and could be the foundation for these
>> data frames.
>>
>
> Depending on your use of the GSL, as I recall the license restricts
> commercial use.
>
> Best regards,
>
> -Tom
>


-- 
Fernando Santagata


Re: Baby steps to create a dataframe structure

2020-07-22 Thread Fernando Santagata
Since you listed R among the other languages, I guess that you're
interested in statistical functions too. If not, discard the rest of this
email :-)

I'm working now on the statistical functions of the GSL: mean, variance,
standard deviation, etc. Those functions are not based on the GSL
vector/matrix interface, so that module will not depend on any other Raku
module.
The functions provided by the library accept arrays in every native data
type[¹] available in Raku (int8, uint8, int16, … num32, num64).
If you're planning to use the fastest approach available, I can split the
module and publish the raw interface separately from the higher level one,
so you'll be able to use NativeCall internally and have the minimal set of
external code.

[¹] libgsl has different functions for each data type.

On Wed, Jul 22, 2020 at 1:42 AM Aureliano Guedes 
wrote:

> Hi all,
>
> I'd like to learn Raku deep enough to build a data structure. I have
> experience with Perl5, Python, R, and even C/C++, then I get boring
> feelings to learn something new from the beginning. Also, I prefer learning
> a new language by applying f to something.
>
> Since I work with data analysis and data science, I'd like to try to
> develop a data structure to dataframe in pure Raku. And if I do a basic but
> useful thing capable to load a field delimited file (as CSV or TSV) into a
> dataframe, I'll transform in a package and upload it to GitHub to
> comparatively enhance the package.
> What I need is suggestions for how do I start it.
> - How I define a data structure: an array of arrays?
> - Given the raku itself (and maybe some already existing packages) what
> the structures and functions I may use.
>
> I got these ideas to start:
>
> The dataframe should support columns name to be called as:
>
> df.column1
>
> and it should return a list of values on this column.
> Also, when it read the delim file it should check each column type.
>
>
> All suggestions are welcome.
>
>
>
> --
> Aureliano Guedes
> skype: aureliano.guedes
> contato:  (11) 94292-6110
> whatsapp +5511942926110
>


-- 
Fernando Santagata


Re: 2020.07 just hit

2020-07-22 Thread Aureliano Guedes
Nice, Daniel,

But, I admit, sometimes I don't like too much some symbols not too
intuitive to do on the keyboard like  ≡ and ≢

Here, I see a lot of codes with weirdo symbols and I need to search how to
do. Anyway, the operator itself seems nice.

On Wed, Jul 22, 2020 at 12:42 AM  wrote:

> > $ raku --version
> > This is Rakudo version 2020.07 built on MoarVM version 2020.07
> > implementing Raku 6.d.
> > Whats is new??
>
> Release notes are at
> https://github.com/rakudo/rakudo/blob/master/docs/announce/2020.07.md
>
> I'm most excited for new the Unicode operators, ≡ and ≢ (though the
> permutations speedup
> is pretty cool too).
>


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


Re: Raku version of "The top 10 tricks of Perl one-liners" ?!?

2020-07-22 Thread Larry Wall
On Sun, Jul 19, 2020 at 09:38:31PM -0700, William Michels via perl6-users wrote:
: Hello,
: 
: I ran across this 2010 Perl(5) article on the Oracle Linux Blog:
: 
: "The top 10 tricks of Perl one-liners"
: https://blogs.oracle.com/linux/the-top-10-tricks-of-perl-one-liners-v2
: 
: Q1. Now that it's a decade later--and Raku (née Perl6) has hit the
: scene--can someone translate the 'top ten tricks' in the blog article
: above into Raku?
: 
: Q2. Are many of the ten Perl(5) one-liner 'tricks' unnecessary in Raku
: (better defaults, more regularized regexes, etc.)?
: 
: Best, Bill.

Yes, and yes.  :-)

More specificially, here's my take.

>   Trick #1: -l
>
>Smart newline processing. Normally, perl hands you entire lines,
>including a trailing newline. With -l, it will strip the trailing
>newline off of any lines read, and automatically add a newline to
>anything you print (including via -p).
>
>Suppose I wanted to strip trailing whitespace from a file. I might
>naïvely try something like
>
>perl -pe 's/\s*$//'
>
>The problem, however, is that the line ends with "\n", which is
>whitespace, and so that snippet will also remove all newlines from
>my file! -l solves the problem, by pulling off the newline before
>handing my script the line, and then tacking a new one on afterwards:
>
>perl -lpe 's/\s*$//'

This trick is not needed in Raku, since newlines are stripped by default.  Also,
there are .trim methods that you can use instead of regex.

>Trick #2: -0
>
>Occasionally, it's useful to run a script over an entire file,
>or over larger chunks at once. -0 makes -n and -p feed you chunks
>split on NULL bytes instead of newlines. This is often useful for,
>e.g. processing the output of find -print0. Furthermore, perl -0777
>makes perl not do any splitting, and pass entire files to your script
>in $_.
>
>find . -name '*~' -print0 | perl -0ne unlink
>
>Could be used to delete all ~-files in a directory tree, without
>having to remember how xargs works.

The key word above is "occasionally", so most of these seldom-used switches are 
gone.
Also, most of their functions are really easy to do from inside the language.
So these days dividing a file by null chars would typicaly be handled with:

for slurp.split("\0") { ... }

>Trick #3: -i
>
>-i tells perl to operate on files in-place. If you use -n or -p with
>-i, and you pass perl filenames on the command-line, perl will run
>your script on those files, and then replace their contents with the
>output. -i optionally accepts an backup suffix as argument; Perl will
>write backup copies of edited files to names with that suffix added.
>
>perl -i.bak -ne 'print unless /^#/' script.sh
>
>Would strip all whole-line commands from script.sh, but leave a copy
>of the original in script.sh.bak.

I'm not aware of a direct replacement for this in Raku.  Perl has to be
better at something...

>Trick #4: The .. operator
>
>Perl's .. operator is a stateful operator -- it remembers state
>between evaluations. As long as its left operand is false, it returns
>false; Once the left hand returns true, it starts evaluating the
>right-hand operand until that becomes true, at which point, on
>the next iteration it resets to false and starts testing the other
>operand again.
>
>What does that mean in practice? It's a range operator: It can be
>easily used to act on a range of lines in a file. For instance,
>I can extract all GPG public keys from a file using:
>
>perl -ne 'print if /-BEGIN PGP PUBLIC KEY BLOCK-/../-END 
> PGP PUBLIC KEY BLOCK-/' FILE

The scalar .. operator in Perl translates to the ff operator in Raku.
It's slightly less magical, however, insofar as it won't treat bare
numbers as line numbers in the input.

>Trick #5: -a
>
>-a turns on autosplit mode – perl will automatically split input
>lines on whitespace into the @F array. If you ever run into any advice
>that accidentally escaped from 1980 telling you to use awk because
>it automatically splits lines into fields, this is how you use perl
>to do the same thing without learning another, even worse, language.
>
>As an example, you could print a list of files along with their link
>counts using
>
>ls -l | perl -lane 'print "$F[7] $F[1]"'

This feature was always a bit suspect because it hard-wired a particular
name.  You don't even need a weird name in Raku:

 ls -l | raku -ne 'say "$_[7] $_[1]" given .words'

>Trick #6: -F
>
>-F is used in conjunction with -a, to choose the delimiter on
>which to split lines. To print every user in /etc/passwd (which is
>colon-separated with the user in

Re: Baby steps to create a dataframe structure

2020-07-22 Thread Aureliano Guedes
I liked all answers, make me more motivated to begin

On Wed, Jul 22, 2020 at 9:24 AM Fernando Santagata <
nando.santag...@gmail.com> wrote:

> Since you listed R among the other languages, I guess that you're
> interested in statistical functions too. If not, discard the rest of this
> email :-)
>

Not only, but also.

Actually, recently I prepared a Jupiter Notebook with Raku kernel just to
play with. Then, in another thread, I saw the implementation of the inner
and outer join operation, then I 'm trying to do the left and right join
too.
I also thought to implement other relational operations (functions) to add
columns, transform columns, summarize, filter, arrange, all common in data
wrangle, and data manipulation, I know all these operations s easy doable
in Raku but the Idea is to make it easy as possible as dictated by Hardley
Wickham  and implemented in dplyr
.

The idea is to prepare a comfortable environment to do data analysis,
resume some data in a good plot , and
etc.

Since Raku deal really nice with rationals and natively deal with async and
concurrency, this language might be wonderous to data analysis and data
science.


> I'm working now on the statistical functions of the GSL: mean, variance,
> standard deviation, etc. Those functions are not based on the GSL
> vector/matrix interface, so that module will not depend on any other Raku
> module.
> The functions provided by the library accept arrays in every native data
> type[¹] available in Raku (int8, uint8, int16, … num32, num64).
> If you're planning to use the fastest approach available, I can split the
> module and publish the raw interface separately from the higher level one,
> so you'll be able to use NativeCall internally and have the minimal set of
> external code.
>
> [¹] libgsl has different functions for each data type.
>
> On Wed, Jul 22, 2020 at 1:42 AM Aureliano Guedes <
> guedes.aureli...@gmail.com> wrote:
>
>> Hi all,
>>
>> I'd like to learn Raku deep enough to build a data structure. I have
>> experience with Perl5, Python, R, and even C/C++, then I get boring
>> feelings to learn something new from the beginning. Also, I prefer learning
>> a new language by applying f to something.
>>
>> Since I work with data analysis and data science, I'd like to try to
>> develop a data structure to dataframe in pure Raku. And if I do a basic but
>> useful thing capable to load a field delimited file (as CSV or TSV) into a
>> dataframe, I'll transform in a package and upload it to GitHub to
>> comparatively enhance the package.
>> What I need is suggestions for how do I start it.
>> - How I define a data structure: an array of arrays?
>> - Given the raku itself (and maybe some already existing packages) what
>> the structures and functions I may use.
>>
>> I got these ideas to start:
>>
>> The dataframe should support columns name to be called as:
>>
>> df.column1
>>
>> and it should return a list of values on this column.
>> Also, when it read the delim file it should check each column type.
>>
>>
>> All suggestions are welcome.
>>
>>
>>
>> --
>> Aureliano Guedes
>> skype: aureliano.guedes
>> contato:  (11) 94292-6110
>> whatsapp +5511942926110
>>
>
>
> --
> Fernando Santagata
>


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


Re: Raku version of "The top 10 tricks of Perl one-liners" ?!?

2020-07-22 Thread Aureliano Guedes
That is a little bit disappointing:

$ time ls -l | perl -lane 'print "$F[7] $F[1]"' > /dev/null

real 0m0.008s
user 0m0.013s
sys 0m0.000s

$ time ls -l | raku -ne 'say "$_[7] $_[1]" given .words' > /dev/null
Use of Nil in string context
  in block  at -e line 1

real 0m0.302s
user 0m0.370s
sys 0m0.060s


The delay is so long that I wouldn't use that in a very filled folder.
Perhaps I know, it will be improved (I hope).

On Wed, Jul 22, 2020 at 4:21 PM Larry Wall  wrote:

> On Sun, Jul 19, 2020 at 09:38:31PM -0700, William Michels via perl6-users
> wrote:
> : Hello,
> :
> : I ran across this 2010 Perl(5) article on the Oracle Linux Blog:
> :
> : "The top 10 tricks of Perl one-liners"
> : https://blogs.oracle.com/linux/the-top-10-tricks-of-perl-one-liners-v2
> :
> : Q1. Now that it's a decade later--and Raku (née Perl6) has hit the
> : scene--can someone translate the 'top ten tricks' in the blog article
> : above into Raku?
> :
> : Q2. Are many of the ten Perl(5) one-liner 'tricks' unnecessary in Raku
> : (better defaults, more regularized regexes, etc.)?
> :
> : Best, Bill.
>
> Yes, and yes.  :-)
>
> More specificially, here's my take.
>
> >   Trick #1: -l
> >
> >Smart newline processing. Normally, perl hands you entire lines,
> >including a trailing newline. With -l, it will strip the trailing
> >newline off of any lines read, and automatically add a newline to
> >anything you print (including via -p).
> >
> >Suppose I wanted to strip trailing whitespace from a file. I might
> >naïvely try something like
> >
> >perl -pe 's/\s*$//'
> >
> >The problem, however, is that the line ends with "\n", which is
> >whitespace, and so that snippet will also remove all newlines from
> >my file! -l solves the problem, by pulling off the newline before
> >handing my script the line, and then tacking a new one on
> afterwards:
> >
> >perl -lpe 's/\s*$//'
>
> This trick is not needed in Raku, since newlines are stripped by default.
> Also,
> there are .trim methods that you can use instead of regex.
>
> >Trick #2: -0
> >
> >Occasionally, it's useful to run a script over an entire file,
> >or over larger chunks at once. -0 makes -n and -p feed you chunks
> >split on NULL bytes instead of newlines. This is often useful for,
> >e.g. processing the output of find -print0. Furthermore, perl
> -0777
> >makes perl not do any splitting, and pass entire files to your
> script
> >in $_.
> >
> >find . -name '*~' -print0 | perl -0ne unlink
> >
> >Could be used to delete all ~-files in a directory tree, without
> >having to remember how xargs works.
>
> The key word above is "occasionally", so most of these seldom-used
> switches are gone.
> Also, most of their functions are really easy to do from inside the
> language.
> So these days dividing a file by null chars would typicaly be handled with:
>
> for slurp.split("\0") { ... }
>
> >Trick #3: -i
> >
> >-i tells perl to operate on files in-place. If you use -n or -p
> with
> >-i, and you pass perl filenames on the command-line, perl will run
> >your script on those files, and then replace their contents with
> the
> >output. -i optionally accepts an backup suffix as argument; Perl
> will
> >write backup copies of edited files to names with that suffix
> added.
> >
> >perl -i.bak -ne 'print unless /^#/' script.sh
> >
> >Would strip all whole-line commands from script.sh, but leave a
> copy
> >of the original in script.sh.bak.
>
> I'm not aware of a direct replacement for this in Raku.  Perl has to be
> better at something...
>
> >Trick #4: The .. operator
> >
> >Perl's .. operator is a stateful operator -- it remembers state
> >between evaluations. As long as its left operand is false, it
> returns
> >false; Once the left hand returns true, it starts evaluating the
> >right-hand operand until that becomes true, at which point, on
> >the next iteration it resets to false and starts testing the other
> >operand again.
> >
> >What does that mean in practice? It's a range operator: It can be
> >easily used to act on a range of lines in a file. For instance,
> >I can extract all GPG public keys from a file using:
> >
> >perl -ne 'print if /-BEGIN PGP PUBLIC KEY
> BLOCK-/../-END PGP PUBLIC KEY BLOCK-/' FILE
>
> The scalar .. operator in Perl translates to the ff operator in Raku.
> It's slightly less magical, however, insofar as it won't treat bare
> numbers as line numbers in the input.
>
> >Trick #5: -a
> >
> >-a turns on autosplit mode – perl will automatically split input
> >lines on whitespace into the @F array. If you ever run into any
> advice
> >that accidentally escaped from 1980 telling you to use awk because
> >   

Re: Raku version of "The top 10 tricks of Perl one-liners" ?!?

2020-07-22 Thread Elizabeth Mattijsen
Larry,

good to see you here!

Of course, I have some comments on your suggestions  :-)


> On 22 Jul 2020, at 21:14, Larry Wall  wrote:
>>   Trick #5: -a
>> 
>>   -a turns on autosplit mode – perl will automatically split input
>>   lines on whitespace into the @F array. If you ever run into any advice
>>   that accidentally escaped from 1980 telling you to use awk because
>>   it automatically splits lines into fields, this is how you use perl
>>   to do the same thing without learning another, even worse, language.
>> 
>>   As an example, you could print a list of files along with their link
>>   counts using
>> 
>>   ls -l | perl -lane 'print "$F[7] $F[1]"'
> This feature was always a bit suspect because it hard-wired a particular
> name.  You don't even need a weird name in Raku:
> 
> ls -l | raku -ne 'say "$_[7] $_[1]" given .words'

ls -l | raku -ne 'put .words[7,1]'

"put" stringifies a slice with a space in between elements.


>>   Trick #6: -F
>> 
>>   -F is used in conjunction with -a, to choose the delimiter on
>>   which to split lines. To print every user in /etc/passwd (which is
>>   colon-separated with the user in the first column), we could do:
>> 
>>   perl -F: -lane 'print $F[0]' /etc/passwd
> 
> Again, we felt this switch wasn't really pulling it's weight, so we pulled it
> in favor of explicit split or comb:
> 
> raku -ne 'say $_[0] given .split(":")' /etc/passwd

raku -ne 'say .split(":").head' /etc/passwd

"head" takes the first element of a Seq *without* needing to cache it, making 
it about twice as fast.

Liz

Re: Raku version of "The top 10 tricks of Perl one-liners" ?!?

2020-07-22 Thread Timo Paulssen
Try it with a very filled folder, though. I would expect the majority of
the time spent is setup and actually going through the lines themselves
isn't very slow.

On 22/07/2020 22:31, Aureliano Guedes wrote:
> That is a little bit disappointing:
>
> $ time ls -l | perl -lane 'print "$F[7] $F[1]"' > /dev/null
>
> real 0m0.008s
> user 0m0.013s
> sys 0m0.000s
>
> $ time ls -l | raku -ne 'say "$_[7] $_[1]" given .words' > /dev/null
> Use of Nil in string context
>   in block  at -e line 1
>
> real 0m0.302s
> user 0m0.370s
> sys 0m0.060s 
>
>
> The delay is so long that I wouldn't use that in a very filled folder.
> Perhaps I know, it will be improved (I hope).   
>
> On Wed, Jul 22, 2020 at 4:21 PM Larry Wall  > wrote:
>
> On Sun, Jul 19, 2020 at 09:38:31PM -0700, William Michels via
> perl6-users wrote:
> : Hello,
> :
> : I ran across this 2010 Perl(5) article on the Oracle Linux Blog:
> :
> : "The top 10 tricks of Perl one-liners"
> :
> https://blogs.oracle.com/linux/the-top-10-tricks-of-perl-one-liners-v2
> :
> : Q1. Now that it's a decade later--and Raku (née Perl6) has hit the
> : scene--can someone translate the 'top ten tricks' in the blog
> article
> : above into Raku?
> :
> : Q2. Are many of the ten Perl(5) one-liner 'tricks' unnecessary
> in Raku
> : (better defaults, more regularized regexes, etc.)?
> :
> : Best, Bill.
>
> Yes, and yes.  :-)
>
> More specificially, here's my take.
>
> >   Trick #1: -l
> >
> >        Smart newline processing. Normally, perl hands you entire
> lines,
> >        including a trailing newline. With -l, it will strip the
> trailing
> >        newline off of any lines read, and automatically add a
> newline to
> >        anything you print (including via -p).
> >
> >        Suppose I wanted to strip trailing whitespace from a
> file. I might
> >        naïvely try something like
> >
> >        perl -pe 's/\s*$//'
> >
> >        The problem, however, is that the line ends with "\n",
> which is
> >        whitespace, and so that snippet will also remove all
> newlines from
> >        my file! -l solves the problem, by pulling off the
> newline before
> >        handing my script the line, and then tacking a new one on
> afterwards:
> >
> >        perl -lpe 's/\s*$//'
>
> This trick is not needed in Raku, since newlines are stripped by
> default.  Also,
> there are .trim methods that you can use instead of regex.
>
> >    Trick #2: -0
> >
> >        Occasionally, it's useful to run a script over an entire
> file,
> >        or over larger chunks at once. -0 makes -n and -p feed
> you chunks
> >        split on NULL bytes instead of newlines. This is often
> useful for,
> >        e.g. processing the output of find -print0. Furthermore,
> perl -0777
> >        makes perl not do any splitting, and pass entire files to
> your script
> >        in $_.
> >
> >        find . -name '*~' -print0 | perl -0ne unlink
> >
> >        Could be used to delete all ~-files in a directory tree,
> without
> >        having to remember how xargs works.
>
> The key word above is "occasionally", so most of these seldom-used
> switches are gone.
> Also, most of their functions are really easy to do from inside
> the language.
> So these days dividing a file by null chars would typicaly be
> handled with:
>
>     for slurp.split("\0") { ... }
>
> >    Trick #3: -i
> >
> >        -i tells perl to operate on files in-place. If you use -n
> or -p with
> >        -i, and you pass perl filenames on the command-line, perl
> will run
> >        your script on those files, and then replace their
> contents with the
> >        output. -i optionally accepts an backup suffix as
> argument; Perl will
> >        write backup copies of edited files to names with that
> suffix added.
> >
> >        perl -i.bak -ne 'print unless /^#/' script.sh
> >
> >        Would strip all whole-line commands from script.sh, but
> leave a copy
> >        of the original in script.sh.bak.
>
> I'm not aware of a direct replacement for this in Raku.  Perl has
> to be
> better at something...
>
> >    Trick #4: The .. operator
> >
> >        Perl's .. operator is a stateful operator -- it remembers
> state
> >        between evaluations. As long as its left operand is
> false, it returns
> >        false; Once the left hand returns true, it starts
> evaluating the
> >        right-hand operand until that becomes true, at which
> point, on
> >        the next iteration it resets to false and starts testing
> the other
> >        operand again.
> >
> >        What does 

Re: Baby steps to create a dataframe structure

2020-07-22 Thread Tessa Plum

JJ Merelo wrote:
The Raku wrapper for GSL is ready, specifically all matrix operations, 
check it out. It's extremely fast, and could be the foundation for these 
data frames.


What's GSL? Global StarCraft League, I google it show me this result.

^_^

Tessa Plum
https://plum.ovh/


Re: Raku version of "The top 10 tricks of Perl one-liners" ?!?

2020-07-22 Thread William Michels via perl6-users
Dear Larry,

Thank you so much for such a complete reply!

Not to keep score here, it seems like 9/10 Perl5 'one-liner tricks'
are baked into Raku from the language's inception. [ The only feature
that might be missing is 'Trick #3' where Perl5 modifies a file
in-place at the bash command line (and can create a backup file
beforehand) ].

Two notes, inline:

>
> >Trick #9: BEGIN and END
> >
> >BEGIN { ... } and END { ... } let you put code that gets run entirely
> >before or after the loop over the lines.
> >
> >For example, I could sum the values in the second column of a CSV
> >file using:
> >
> >perl -F, -lane '$t += $F[1]; END { print $t }'
>
> Same trick, except you can omit the brackets:
>
>  raku -ne 'my $t += [1] given .split(","); END say $t'
>
> Note the 'my' is required because strict is the default.

The way I got this to work in Raku was to put a period before the
indexing '[1]', otherwise it appears Raku returns the total number of
lines read:

raku -ne 'my $t += .[1] given .split(","); END say $t'

The two lines below work also (TMTOWTDI), although one or both might
be less readable than Larry's code above. However, the second
one-liner below might look very familiar to R-users
(https://www.r-project.org), because it has a method call with
arguments enclosed by parentheses, followed directly by a
post-circumfix indexing call using square brackets:

raku -ne 'my $t += .split(",").[1]; END say $t'

#OR

raku -ne 'my $t += .split(",")[1]; END say $t'

>
> >Trick #10: -MRegexp::Common
> >
> >Using -M on the command line tells perl to load the given module
> >before running your code. There are thousands of modules available
> >on CPAN, numerous of them potentially useful in one-liners, but
> >one of my favorite for one-liner use is Regexp::Common, which, as
> >its name suggests, contains regular expressions to match numerous
> >commonly-used pieces of data.
> >
> >The full set of regexes available in Regexp::Common is available in
> >its documentation, but here's an example of where I might use it:
> >
> >Neither the ifconfig nor the ip tool that is supposed to replace it
> >provide, as far as I know, an easy way of extracting information for
> >use by scripts. The ifdata program provides such an interface, but
> >isn't installed everywhere. Using perl and Regexp::Common, however,
> >we can do a pretty decent job of extracing an IP from ips output:
> >
> >ip address list eth0 | \
> >  perl -MRegexp::Common -lne 'print $1 if /($RE{net}{IPv4})/'
>
> I don't know if there's anything quite comparable.  And who's to say
> what's "common" anymore...   Certainly we have -M.  But Raku's regex
> and grammars are so much more powerful that these things are likely to
> kept in more specific Grammar modules anyway, or just hand-rolled for
> the purpose on the spot.
>
> >~nelhage Join the discussion Comments ( 7 )
>
> Larry

I took a quick look at Perl5's Regexp::Common module on CPAN and found
this list of patterns:  balanced, comment, delimited, lingua, list,
net, number, whitespace, zip. Many of the important patterns seem
baked into the Raku language already (whitespace, balanced,
delimited). I guess it's easy enough to load a Raku module providing
regex patterns in the same way as loading a Perl(5 or 7) module, since
the -M flag is identical. Or, someone savvy could load a Perl(5)
module in Raku via NativeCall.

But Raku one-liners with modules work fine. Below (if anyone wants
some code to play around with), I scraped the Raku.org home page using
Raku's "HTML::Strip" module. Works like a charm:

wget -O - "http://raku.org"; | raku -MHTML::Strip -ne 'strip_html($_).say'


Thank you again, Larry!

Best, Bill.

W. Michels, Ph.D.


Re: Baby steps to create a dataframe structure

2020-07-22 Thread William Michels via perl6-users
Hi Tessa, see:

"GNU Scientific Library"
https://www.gnu.org/software/gsl/

HTH, Bill.


On Wed, Jul 22, 2020 at 5:16 PM Tessa Plum  wrote:
>
> JJ Merelo wrote:
> > The Raku wrapper for GSL is ready, specifically all matrix operations,
> > check it out. It's extremely fast, and could be the foundation for these
> > data frames.
>
> What's GSL? Global StarCraft League, I google it show me this result.
>
> ^_^
>
> Tessa Plum
> https://plum.ovh/