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