Re: anything faster than say [+] lines?

2019-09-26 Thread Brad Gilbert
With the Perl5 compiler the -n flag literally adds this around your code before compiling: while ( <> ) { … } Rakudo handles -n by transforming the AST (or the bytecode) into something that loops. Basically it is more like: … for lines (In that it doesn't affect scoping or

Re: anything faster than say [+] lines?

2019-09-26 Thread Andy Bach
> Could the "-e" flag be limiting variable initializations to one? I don't think so. I recall the -n being shorthand for wrapping your -e program in while ( <> ) { # your program here } (-p just adds a continue "print" block, I believe), as folks would do cool tricks of writing their -e script

Re: anything faster than say [+] lines?

2019-09-26 Thread Joseph Brenner
> I see that Int/Num error, What platform are you using? I believe William Michels is on OSX. > and also would like an explanation as to why "my > Int $y" isn't re-initialized to Any each time through this loop So the question is if "-n" is exactly equivalent to wrapping the given code in a loo

Re: anything faster than say [+] lines?

2019-09-26 Thread William Michels via perl6-users
Hi Yary, Honestly, I just tried re-writing the fastest StackOverflow answer (written in Perl 5) that I found below, in Perl 6. To write P5 as P6 I had to declare the variable $x with 'my'. Then I played around with a declaration restricting to "Int" type (to look at potential performance hits), ju

Re: anything faster than say [+] lines?

2019-09-26 Thread Joseph Brenner
Um, okay, But I'm still seeing the same behavior Andy is, using the last rakudo star release 2019.03.1, Perl 6.d: seq 100 | perl6 -ne 'my Int $y += $_; END { print $y; }' 5050 This is on linux, (32 bit Debian 9, aka stretch). On 9/26/19, Andy Bach wrote: >> Still, it's just

Re: anything faster than say [+] lines?

2019-09-26 Thread yary
I see that Int/Num error, and also would like an explanation as to why "my Int $y" isn't re-initialized to Any each time through this loop $ seq 100 | perl6 -ne 'my Int $y += $_; END { print $y; }' Type check failed in assignment to $y; expected Int but got Num (5050e0) in block a

Re: anything faster than say [+] lines?

2019-09-26 Thread William Michels via perl6-users
Thank you, Andy and Joseph! On Thu, Sep 26, 2019 at 8:47 AM Andy Bach wrote: > > > Still, it's just "works for me": > > seq 100 | time perl6 -ne 'my $y += $_; END { print $y; }' > > I think that's still the wrong one - your missing the "Int" > $ seq 100 | perl6 -ne 'my Int $y += $_; END

Re: anything faster than say [+] lines?

2019-09-26 Thread Andy Bach
> Still, it's just "works for me": seq 100 | time perl6 -ne 'my $y += $_; END { print $y; }' I think that's still the wrong one - your missing the "Int" $ seq 100 | perl6 -ne 'my Int $y += $_; END { print $y; }' 5050 though that works here, admittedly, my p6 is sort old This is