Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$*IN.ins doesn't count the number of iterations so far in a -n loop in Rakudo #2777

Closed
p6rt opened this issue May 26, 2012 · 7 comments
Closed

Comments

@p6rt
Copy link

p6rt commented May 26, 2012

Migrated from rt.perl.org#113100 (status was 'resolved')

Searchable as RT113100$

@p6rt
Copy link
Author

p6rt commented May 26, 2012

From @masak

<masak> in a perl6 -n loop, is $*IN.ins supposed to count each
iteration, just like $. does in Perl 5?
<masak> because it doesn't. :(

$ ./perl6 -n -e 'say $*IN.ins'
foo
bar
baz
0
0
0

<moritz> I think .ins only works well with .get, not with .lines
<masak> I think .ins should measure the number of records read,
regardless of method.
* masak submits rakudobug
<moritz> masak​: it's not so easy
<moritz> masak​: because it depends on the reification model used by for/map
<masak> I was just getting to that.
<masak> seems -n doesn't run stuff until I ^D
<masak> that's... unfortunate.

@p6rt
Copy link
Author

p6rt commented May 26, 2012

From @masak

<masak> moritz​: is there something about `eager` that's still NYI that
makes Rakudo -n not run code ASAP?
<masak> or are you saying "it's a feature, not a bug"?
<masak> because it seems to me we keep running into situations where the
bit of spec that says "&map (or gather, rather) is allowed to buffer a
few elements ahead" breaks reasonable expectations.
<jnthn> masak​: We already know map is too eager.
<jnthn> masak​: It's on Pm's todo list already.
<moritz> yes, there's a submitted bug for that
<moritz> and it's the .munch($argc * $count) thing that was discussed
yesterday or so
<jnthn> Right.
<masak> oh, ok.
<masak> but $*IN.ins is almost-but-not-quite orthogonal, I guess.
<moritz> no
<moritz> .lines calls .get internally
<moritz> so on a strictly lazy iteration, .ins is always in sync with
the iterator
<masak> i.e. I'll merge this ticket with the one that already talks
about map being too eager?
<moritz> +1
* masak makes it so
<colomon> maybe I'm being dense, but I don't see how .ins can make sense
with .lines.
<colomon> unless you're looking for the total number of lines
<masak> .lines reads all lines by default. it also takes an argument, in
which case it doesn't.
<masak> .ins should work like $. , IMHO.
<colomon> masak​: but it doesn't really make sense in a possibly lazy
context.
<moritz> r​: sub l { gather while !$*IN.eof { take get } }; my $x = l()
[2]; say $*IN.ins
<p6eval> rakudo e75663​: OUTPUT«0␤»
<moritz> r​: sub l { gather while !$*IN.eof { take $*IN.get } }; my $x =
l()[2]; say $*IN.ins
<p6eval> rakudo e75663​: OUTPUT«3␤»
<moritz> OH
<moritz> it's $*ARGS vs. $*IN
<colomon> who'd win?
* moritz
<masak> if $*ARGS.ins works like I want, I'll happily let moritz win ;)
<moritz> erm, ARGFILES, sorry
<masak> woddeva.
<moritz> but it doesn't seem to work either
<masak> right. for the above reasons.
<moritz> I'm not convinced
<moritz> because it always says 0
<moritz> but it really should say the last line number all over, no?
<moritz> r​: class A { has $.x }; class B is A { has $.x; method set() {
$!x = 5 } }; given B.new { .set; say .x }
<p6eval> rakudo e75663​: OUTPUT«5␤»
<moritz> the problem is that IO​::ArgFiles inherits from IO
<moritz> and has it own $!ins
<moritz> but not its own accessor
<moritz> IO​::ArgFiles.ins returns $!ins from class IO, which is still 0
<masak> huh.
<moritz> masak​: fun, eh?
<masak> sounds like something's askew somewhere...
<moritz> but a single-character fix
<masak> \o/
<dalek> rakudo/qbootstrap​: 51f1b93 | moritz++ | src/core/IO/ArgFiles.pm​:
<dalek> rakudo/qbootstrap​: fix IO​::ArgFiles.ins
<dalek> rakudo/qbootstrap​: review​:
https://github.com/rakudo/rakudo/commit/51f1b934ac
<moritz> now it returns the number of the last line all over, as I
expected :-)
<moritz> r​: for lines() { print $*ARGFILES.get }
<p6eval> rakudo e75663​: OUTPUT«End of argfiles reached [...]
<moritz> r​: for lines() { print $*ARGFILES.ins }
<p6eval> rakudo e75663​: OUTPUT«00000000000000000000000»
* masak adds all this to le ticket

@p6rt
Copy link
Author

p6rt commented May 26, 2012

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 24, 2015

From @perlpilot

These currently work as expected​:

➤ wc -l test.dat
3 test.dat

➤ perl6 -n -e 'say $*ARGFILES.ins' test.dat
1
2
3

➤ cat test.dat | perl6 -n -e 'say $*ARGFILES.ins'
1
2
3

➤ cat test.dat | perl6 -n -e 'say $*ARGFILES.ins' -
1
2
3

➤ perl6 -n -e 'say $*IN.ins' test.dat
0
0
0

For the last one we're not reading from $*IN, so we're always at line "0" However, these do not work as expected​:

➤ perl6 -n -e 'say $*IN.ins' < test.dat
0
0
0

➤ cat test.dat | perl6 -n -e 'say $*IN.ins'
0
0
0

➤ cat test.dat | perl6 -n -e 'say $*IN.ins' -
0
0
0

In each case we're reading from stdin which should be $*IN within Perl 6, but I believe the current implementation opens new filehandles for stdin in these cases, so $*IN is never updated as we read.

On Sat May 26 09​:04​:34 2012, masak wrote​:

<masak> moritz​: is there something about `eager` that's still NYI that
makes Rakudo -n not run code ASAP?
<masak> or are you saying "it's a feature, not a bug"?
<masak> because it seems to me we keep running into situations where the
bit of spec that says "&map (or gather, rather) is allowed to buffer a
few elements ahead" breaks reasonable expectations.
<jnthn> masak​: We already know map is too eager.
<jnthn> masak​: It's on Pm's todo list already.
<moritz> yes, there's a submitted bug for that
<moritz> and it's the .munch($argc * $count) thing that was discussed
yesterday or so
<jnthn> Right.
<masak> oh, ok.
<masak> but $*IN.ins is almost-but-not-quite orthogonal, I guess.
<moritz> no
<moritz> .lines calls .get internally
<moritz> so on a strictly lazy iteration, .ins is always in sync with
the iterator
<masak> i.e. I'll merge this ticket with the one that already talks
about map being too eager?
<moritz> +1
* masak makes it so
<colomon> maybe I'm being dense, but I don't see how .ins can make sense
with .lines.
<colomon> unless you're looking for the total number of lines
<masak> .lines reads all lines by default. it also takes an argument, in
which case it doesn't.
<masak> .ins should work like $. , IMHO.
<colomon> masak​: but it doesn't really make sense in a possibly lazy
context.
<moritz> r​: sub l { gather while !$*IN.eof { take get } }; my $x = l()
[2]; say $*IN.ins
<p6eval> rakudo e75663​: OUTPUT«0␤»
<moritz> r​: sub l { gather while !$*IN.eof { take $*IN.get } }; my $x =
l()[2]; say $*IN.ins
<p6eval> rakudo e75663​: OUTPUT«3␤»
<moritz> OH
<moritz> it's $*ARGS vs. $*IN
<colomon> who'd win?
* moritz
<masak> if $*ARGS.ins works like I want, I'll happily let moritz win ;)
<moritz> erm, ARGFILES, sorry
<masak> woddeva.
<moritz> but it doesn't seem to work either
<masak> right. for the above reasons.
<moritz> I'm not convinced
<moritz> because it always says 0
<moritz> but it really should say the last line number all over, no?
<moritz> r​: class A { has $.x }; class B is A { has $.x; method set() {
$!x = 5 } }; given B.new { .set; say .x }
<p6eval> rakudo e75663​: OUTPUT«5␤»
<moritz> the problem is that IO​::ArgFiles inherits from IO
<moritz> and has it own $!ins
<moritz> but not its own accessor
<moritz> IO​::ArgFiles.ins returns $!ins from class IO, which is still 0
<masak> huh.
<moritz> masak​: fun, eh?
<masak> sounds like something's askew somewhere...
<moritz> but a single-character fix
<masak> \o/
<dalek> rakudo/qbootstrap​: 51f1b93 | moritz++ | src/core/IO/ArgFiles.pm​:
<dalek> rakudo/qbootstrap​: fix IO​::ArgFiles.ins
<dalek> rakudo/qbootstrap​: review​:
https://github.com/rakudo/rakudo/commit/51f1b934ac
<moritz> now it returns the number of the last line all over, as I
expected :-)
<moritz> r​: for lines() { print $*ARGFILES.get }
<p6eval> rakudo e75663​: OUTPUT«End of argfiles reached [...]
<moritz> r​: for lines() { print $*ARGFILES.ins }
<p6eval> rakudo e75663​: OUTPUT«00000000000000000000000»
* masak adds all this to le ticket

--

-Scott (PerlJam/perlpilot)

@p6rt
Copy link
Author

p6rt commented Jul 24, 2015

From @perlpilot

With commit rakudo/rakudo@6f292f5

Now works as expected​:

➤ ./perl6 -n -e 'say $*IN.ins' < test.dat
1
2
3

➤ cat test.dat | ./perl6 -n -e 'say $*IN.ins'
1
2
3

➤ cat test.dat | ./perl6 -n -e 'say $*IN.ins' -
1
2
3

Still needs tests.

On Fri Jul 24 08​:23​:12 2015, duff wrote​:

These currently work as expected​:

➤ wc -l test.dat
3 test.dat

➤ perl6 -n -e 'say $*ARGFILES.ins' test.dat
1
2
3

➤ cat test.dat | perl6 -n -e 'say $*ARGFILES.ins'
1
2
3

➤ cat test.dat | perl6 -n -e 'say $*ARGFILES.ins' -
1
2
3

➤ perl6 -n -e 'say $*IN.ins' test.dat
0
0
0

For the last one we're not reading from $*IN, so we're always at line
"0" However, these do not work as expected​:

➤ perl6 -n -e 'say $*IN.ins' < test.dat
0
0
0

➤ cat test.dat | perl6 -n -e 'say $*IN.ins'
0
0
0

➤ cat test.dat | perl6 -n -e 'say $*IN.ins' -
0
0
0

In each case we're reading from stdin which should be $*IN within Perl
6, but I believe the current implementation opens new filehandles for
stdin in these cases, so $*IN is never updated as we read.

On Sat May 26 09​:04​:34 2012, masak wrote​:

<masak> moritz​: is there something about `eager` that's still NYI
that
makes Rakudo -n not run code ASAP?
<masak> or are you saying "it's a feature, not a bug"?
<masak> because it seems to me we keep running into situations where
the
bit of spec that says "&map (or gather, rather) is allowed to buffer
a
few elements ahead" breaks reasonable expectations.
<jnthn> masak​: We already know map is too eager.
<jnthn> masak​: It's on Pm's todo list already.
<moritz> yes, there's a submitted bug for that
<moritz> and it's the .munch($argc * $count) thing that was discussed
yesterday or so
<jnthn> Right.
<masak> oh, ok.
<masak> but $*IN.ins is almost-but-not-quite orthogonal, I guess.
<moritz> no
<moritz> .lines calls .get internally
<moritz> so on a strictly lazy iteration, .ins is always in sync with
the iterator
<masak> i.e. I'll merge this ticket with the one that already talks
about map being too eager?
<moritz> +1
* masak makes it so
<colomon> maybe I'm being dense, but I don't see how .ins can make
sense
with .lines.
<colomon> unless you're looking for the total number of lines
<masak> .lines reads all lines by default. it also takes an argument,
in
which case it doesn't.
<masak> .ins should work like $. , IMHO.
<colomon> masak​: but it doesn't really make sense in a possibly lazy
context.
<moritz> r​: sub l { gather while !$*IN.eof { take get } }; my $x =
l()
[2]; say $*IN.ins
<p6eval> rakudo e75663​: OUTPUT«0␤»
<moritz> r​: sub l { gather while !$*IN.eof { take $*IN.get } }; my $x

l()[2]; say $*IN.ins
<p6eval> rakudo e75663​: OUTPUT«3␤»
<moritz> OH
<moritz> it's $*ARGS vs. $*IN
<colomon> who'd win?
* moritz
<masak> if $*ARGS.ins works like I want, I'll happily let moritz win
;)
<moritz> erm, ARGFILES, sorry
<masak> woddeva.
<moritz> but it doesn't seem to work either
<masak> right. for the above reasons.
<moritz> I'm not convinced
<moritz> because it always says 0
<moritz> but it really should say the last line number all over, no?
<moritz> r​: class A { has $.x }; class B is A { has $.x; method set()
{
$!x = 5 } }; given B.new { .set; say .x }
<p6eval> rakudo e75663​: OUTPUT«5␤»
<moritz> the problem is that IO​::ArgFiles inherits from IO
<moritz> and has it own $!ins
<moritz> but not its own accessor
<moritz> IO​::ArgFiles.ins returns $!ins from class IO, which is still
0
<masak> huh.
<moritz> masak​: fun, eh?
<masak> sounds like something's askew somewhere...
<moritz> but a single-character fix
<masak> \o/
<dalek> rakudo/qbootstrap​: 51f1b93 | moritz++ |
src/core/IO/ArgFiles.pm​:
<dalek> rakudo/qbootstrap​: fix IO​::ArgFiles.ins
<dalek> rakudo/qbootstrap​: review​:
https://github.com/rakudo/rakudo/commit/51f1b934ac
<moritz> now it returns the number of the last line all over, as I
expected :-)
<moritz> r​: for lines() { print $*ARGFILES.get }
<p6eval> rakudo e75663​: OUTPUT«End of argfiles reached [...]
<moritz> r​: for lines() { print $*ARGFILES.ins }
<p6eval> rakudo e75663​: OUTPUT«00000000000000000000000»
* masak adds all this to le ticket

--

-Scott (PerlJam/perlpilot)

@p6rt
Copy link
Author

p6rt commented Jul 25, 2015

From @perlpilot

Tests added in Raku/roast@e8821d1

On Fri Jul 24 09​:31​:29 2015, duff wrote​:

With commit
rakudo/rakudo@6f292f5

Now works as expected​:

➤ ./perl6 -n -e 'say $*IN.ins' < test.dat
1
2
3

➤ cat test.dat | ./perl6 -n -e 'say $*IN.ins'
1
2
3

➤ cat test.dat | ./perl6 -n -e 'say $*IN.ins' -
1
2
3

Still needs tests.

On Fri Jul 24 08​:23​:12 2015, duff wrote​:

These currently work as expected​:

➤ wc -l test.dat
3 test.dat

➤ perl6 -n -e 'say $*ARGFILES.ins' test.dat
1
2
3

➤ cat test.dat | perl6 -n -e 'say $*ARGFILES.ins'
1
2
3

➤ cat test.dat | perl6 -n -e 'say $*ARGFILES.ins' -
1
2
3

➤ perl6 -n -e 'say $*IN.ins' test.dat
0
0
0

For the last one we're not reading from $*IN, so we're always at line
"0" However, these do not work as expected​:

➤ perl6 -n -e 'say $*IN.ins' < test.dat
0
0
0

➤ cat test.dat | perl6 -n -e 'say $*IN.ins'
0
0
0

➤ cat test.dat | perl6 -n -e 'say $*IN.ins' -
0
0
0

In each case we're reading from stdin which should be $*IN within
Perl
6, but I believe the current implementation opens new filehandles for
stdin in these cases, so $*IN is never updated as we read.

On Sat May 26 09​:04​:34 2012, masak wrote​:

<masak> moritz​: is there something about `eager` that's still NYI
that
makes Rakudo -n not run code ASAP?
<masak> or are you saying "it's a feature, not a bug"?
<masak> because it seems to me we keep running into situations
where
the
bit of spec that says "&map (or gather, rather) is allowed to
buffer
a
few elements ahead" breaks reasonable expectations.
<jnthn> masak​: We already know map is too eager.
<jnthn> masak​: It's on Pm's todo list already.
<moritz> yes, there's a submitted bug for that
<moritz> and it's the .munch($argc * $count) thing that was
discussed
yesterday or so
<jnthn> Right.
<masak> oh, ok.
<masak> but $*IN.ins is almost-but-not-quite orthogonal, I guess.
<moritz> no
<moritz> .lines calls .get internally
<moritz> so on a strictly lazy iteration, .ins is always in sync
with
the iterator
<masak> i.e. I'll merge this ticket with the one that already talks
about map being too eager?
<moritz> +1
* masak makes it so
<colomon> maybe I'm being dense, but I don't see how .ins can make
sense
with .lines.
<colomon> unless you're looking for the total number of lines
<masak> .lines reads all lines by default. it also takes an
argument,
in
which case it doesn't.
<masak> .ins should work like $. , IMHO.
<colomon> masak​: but it doesn't really make sense in a possibly
lazy
context.
<moritz> r​: sub l { gather while !$*IN.eof { take get } }; my $x =
l()
[2]; say $*IN.ins
<p6eval> rakudo e75663​: OUTPUT«0␤»
<moritz> r​: sub l { gather while !$*IN.eof { take $*IN.get } }; my
$x

l()[2]; say $*IN.ins
<p6eval> rakudo e75663​: OUTPUT«3␤»
<moritz> OH
<moritz> it's $*ARGS vs. $*IN
<colomon> who'd win?
* moritz
<masak> if $*ARGS.ins works like I want, I'll happily let moritz
win
;)
<moritz> erm, ARGFILES, sorry
<masak> woddeva.
<moritz> but it doesn't seem to work either
<masak> right. for the above reasons.
<moritz> I'm not convinced
<moritz> because it always says 0
<moritz> but it really should say the last line number all over,
no?
<moritz> r​: class A { has $.x }; class B is A { has $.x; method
set()
{
$!x = 5 } }; given B.new { .set; say .x }
<p6eval> rakudo e75663​: OUTPUT«5␤»
<moritz> the problem is that IO​::ArgFiles inherits from IO
<moritz> and has it own $!ins
<moritz> but not its own accessor
<moritz> IO​::ArgFiles.ins returns $!ins from class IO, which is
still
0
<masak> huh.
<moritz> masak​: fun, eh?
<masak> sounds like something's askew somewhere...
<moritz> but a single-character fix
<masak> \o/
<dalek> rakudo/qbootstrap​: 51f1b93 | moritz++ |
src/core/IO/ArgFiles.pm​:
<dalek> rakudo/qbootstrap​: fix IO​::ArgFiles.ins
<dalek> rakudo/qbootstrap​: review​:
https://github.com/rakudo/rakudo/commit/51f1b934ac
<moritz> now it returns the number of the last line all over, as I
expected :-)
<moritz> r​: for lines() { print $*ARGFILES.get }
<p6eval> rakudo e75663​: OUTPUT«End of argfiles reached [...]
<moritz> r​: for lines() { print $*ARGFILES.ins }
<p6eval> rakudo e75663​: OUTPUT«00000000000000000000000»
* masak adds all this to le ticket

--

-Scott (PerlJam/perlpilot)

@p6rt
Copy link
Author

p6rt commented Jul 25, 2015

@perlpilot - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant