Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Once a List is infinite, it stays infinite
Fixes:
$ my @r = ^Inf; say @r.infinite; @r[^10]; say @r.infinite'
True
Nil
  • Loading branch information
lizmat committed Apr 17, 2015
1 parent 9449e15 commit eaf99c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Perl6/Metamodel/BOOTSTRAP.nqp
Expand Up @@ -2613,6 +2613,7 @@ BEGIN {
List.HOW.add_attribute(List, scalar_attr('$!items', Mu, List));
List.HOW.add_attribute(List, scalar_attr('$!flattens', Mu, List));
List.HOW.add_attribute(List, scalar_attr('$!nextiter', Mu, List));
List.HOW.add_attribute(List, scalar_attr('$!infinite', Any, List));
List.HOW.compose_repr(List);

# class Array is List {
Expand Down
5 changes: 4 additions & 1 deletion src/core/List.pm
Expand Up @@ -39,6 +39,7 @@ my class List does Positional { # declared in BOOTSTRAP
# has Mu $!items; # VM's array of our reified elements
# has Mu $!flattens; # true if this list flattens its parcels
# has Mu $!nextiter; # iterator for generating remaining elements
# has Any $!infinite; # is this list infinite or not

method new(|) {
my Mu $args := nqp::p6argvmarray();
Expand Down Expand Up @@ -150,7 +151,9 @@ my class List does Positional { # declared in BOOTSTRAP
$count
}

multi method infinite(List:D:) { $!nextiter.infinite }
multi method infinite(List:D:) {
$!infinite ||= ?$!nextiter.infinite;
}

method iterator() {
# Return a reified ListIter containing our currently reified elements
Expand Down

0 comments on commit eaf99c2

Please sign in to comment.