Skip to content

Commit

Permalink
Remove unnecessary implementation detail
Browse files Browse the repository at this point in the history
&SEQUENCE somehow lived in the CORE:: but didn't need to.  Move
it into Rakudo::SEQUENCE and rename the sub to "iterator", as
that is the most logical thing to be returned from a SEQUENCE
generator.  Adapt the code and the keys tests accordingly.
  • Loading branch information
lizmat committed Mar 20, 2020
1 parent fbf54e1 commit 509a7f6
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 17 deletions.
11 changes: 8 additions & 3 deletions src/core.c/Rakudo/SEQUENCE.pm6
@@ -1,4 +1,7 @@
sub SEQUENCE(\left, Mu \right, :$exclude_end) is implementation-detail {
class Rakudo::SEQUENCE {

method iterator(\left, Mu \right, :$exclude_end --> Iterator:D) {

my \righti := (nqp::iscont(right) ?? right !! [right]).iterator;
my $endpoint := righti.pull-one.self; # .self explodes Failures
$endpoint =:= IterationEnd and X::Cannot::Empty.new(
Expand Down Expand Up @@ -346,8 +349,10 @@ sub SEQUENCE(\left, Mu \right, :$exclude_end) is implementation-detail {
}
});
$infinite
?? (gathered.Slip, Slip.from-iterator(righti)).lazy
!! (gathered.Slip, Slip.from-iterator(righti))
?? (gathered.Slip, Slip.from-iterator(righti)).lazy.iterator
!! (gathered.Slip, Slip.from-iterator(righti)).iterator
}

}

# vim: ft=perl6 expandtab sw=4
7 changes: 4 additions & 3 deletions src/core.c/Range.pm6
@@ -1,3 +1,4 @@
my class Rakudo::SEQUENCE { ... }
my class X::Immutable { ... }
my class X::Range::InvalidArg { ... }

Expand Down Expand Up @@ -157,11 +158,11 @@ my class Range is Cool does Iterable does Positional {
$!min,$!max.Str,$!excludes-min,$!excludes-max
)
# generic string sequence
!! SEQUENCE(
!! Rakudo::SEQUENCE.iterator(
($!excludes-min ?? $!min.succ !! $!min),
$!max,
:exclude_end($!excludes-max)
).iterator
)
# general case
!! Rakudo::Iterator.SuccFromTo(
$!excludes-min ?? $!min.succ !! $!min,
Expand Down Expand Up @@ -303,7 +304,7 @@ my class Range is Cool does Iterable does Positional {
?? ().iterator
!! $max.chars == 1 && nqp::istype($!min,Str) && $!min.chars == 1
?? CharReverse.new($max,$!excludes-min ?? $!min.succ !! $!min)
!! SEQUENCE($max,$!min,:exclude_end($!excludes-min)).iterator
!! Rakudo::SEQUENCE.iterator($max,$!min,:exclude_end($!excludes-min))
}

# General case according to spec
Expand Down
12 changes: 8 additions & 4 deletions src/core.c/operators.pm6
Expand Up @@ -123,7 +123,9 @@ only sub HOW (Mu \x) { x.HOW }
only sub VAR (Mu \x) { x.VAR }

proto sub infix:<...>(|) {*}
multi sub infix:<...>(\a, Mu \b) { Seq.new(SEQUENCE(a, b).iterator) }
multi sub infix:<...>(\a, Mu \b) {
Seq.new(Rakudo::SEQUENCE.iterator(a, b))
}
multi sub infix:<...>(|lol) {
my @lol := lol.list;
my @end;
Expand All @@ -146,11 +148,11 @@ multi sub infix:<...>(|lol) {
$i = 0;
while $i < $m {
$ret := ($ret.Slip,
SEQUENCE(
Seq.new(Rakudo::SEQUENCE.iterator(
(Slip.from-iterator(@seq[$i]),),
@end[$i],
:exclude_end(so @excl[$i])
).Slip
)).Slip
);
++$i;
}
Expand All @@ -163,7 +165,9 @@ multi sub infix:<...>(|lol) {
}

proto sub infix:<...^>($, Mu, *%) {*}
multi sub infix:<...^>(\a, Mu \b) { Seq.new(SEQUENCE(a, b, :exclude_end(1)).iterator) }
multi sub infix:<...^>(\a, Mu \b) {
Seq.new(Rakudo::SEQUENCE.iterator(a, b, :exclude_end))
}

proto sub infix:<>(|) {*}
multi sub infix:<>(|c) { infix:<...>(|c) }
Expand Down
1 change: 0 additions & 1 deletion t/02-rakudo/03-corekeys-6c.t
Expand Up @@ -67,7 +67,6 @@ my @expected = (
Q{&REQUIRE_IMPORT},
Q{&RETURN-LIST},
Q{&RUN-MAIN},
Q{&SEQUENCE},
Q{&SLICE_MORE_HASH},
Q{&SLICE_MORE_LIST},
Q{&SLICE_ONE_HASH},
Expand Down
1 change: 0 additions & 1 deletion t/02-rakudo/03-corekeys-6d.t
Expand Up @@ -67,7 +67,6 @@ my @expected = (
Q{&REQUIRE_IMPORT},
Q{&RETURN-LIST},
Q{&RUN-MAIN},
Q{&SEQUENCE},
Q{&SLICE_MORE_HASH},
Q{&SLICE_MORE_LIST},
Q{&SLICE_ONE_HASH},
Expand Down
1 change: 0 additions & 1 deletion t/02-rakudo/03-corekeys-6e.t
Expand Up @@ -68,7 +68,6 @@ my @expected = (
Q{&REQUIRE_IMPORT},
Q{&RETURN-LIST},
Q{&RUN-MAIN},
Q{&SEQUENCE},
Q{&SLICE_MORE_HASH},
Q{&SLICE_MORE_LIST},
Q{&SLICE_ONE_HASH},
Expand Down
1 change: 0 additions & 1 deletion t/02-rakudo/03-corekeys.t
Expand Up @@ -69,7 +69,6 @@ my @allowed =
Q{&REQUIRE_IMPORT},
Q{&RETURN-LIST},
Q{&RUN-MAIN},
Q{&SEQUENCE},
Q{&SLICE_MORE_HASH},
Q{&SLICE_MORE_LIST},
Q{&SLICE_ONE_HASH},
Expand Down
1 change: 0 additions & 1 deletion t/02-rakudo/04-settingkeys-6c.t
Expand Up @@ -66,7 +66,6 @@ my %allowed = (
Q{&REQUIRE_IMPORT},
Q{&RETURN-LIST},
Q{&RUN-MAIN},
Q{&SEQUENCE},
Q{&SLICE_MORE_HASH},
Q{&SLICE_MORE_LIST},
Q{&SLICE_ONE_HASH},
Expand Down
1 change: 0 additions & 1 deletion t/02-rakudo/04-settingkeys-6e.t
Expand Up @@ -65,7 +65,6 @@ my %allowed = (
Q{&REQUIRE_IMPORT},
Q{&RETURN-LIST},
Q{&RUN-MAIN},
Q{&SEQUENCE},
Q{&SLICE_MORE_HASH},
Q{&SLICE_MORE_LIST},
Q{&SLICE_ONE_HASH},
Expand Down
2 changes: 1 addition & 1 deletion tools/templates/6.c/core_sources
Expand Up @@ -150,8 +150,8 @@ src/core.c/set_precedes.pm6
src/core.c/ObjAt.pm6
src/core.c/Version.pm6
src/core.c/ForeignCode.pm6
src/core.c/operators.pm6
src/core.c/Rakudo/SEQUENCE.pm6
src/core.c/operators.pm6
src/core.c/Hyper.pm6
src/core.c/metaops.pm6
src/core.c/precedence.pm6
Expand Down

0 comments on commit 509a7f6

Please sign in to comment.