Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
start working on higher arity endpoint codes for SEQUENCE
  • Loading branch information
timo committed Dec 25, 2013
1 parent 6d54dc8 commit 6c13c21
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/core/operators.pm
Expand Up @@ -86,6 +86,9 @@ sub SEQUENCE($left, Mu $right, :$exclude_end) {
my $infinite = $endpoint ~~ Whatever || $endpoint === $Inf;
$endpoint = Bool::False if $infinite;
my $tail := ().list;
my int $end_code_arity = -1;
my $end_tail := ().list;
$end_code_arity = $endpoint.arity if $endpoint ~~ Code;

my sub succpred($cmp) {
($cmp < 0) ?? { $^x.succ } !! ( $cmp > 0 ?? { $^x.pred } !! { $^x } )
Expand All @@ -101,8 +104,12 @@ sub SEQUENCE($left, Mu $right, :$exclude_end) {
my $stop;
while @left {
$value = @left.shift;
$end_tail.push($value);
if $value ~~ Code { $code = $value; last }
if $value ~~ $endpoint { $stop = 1; last }
if $end_code_arity > 1 {
$end_tail.munch($end_tail.elems - $end_code_arity);
if $endpoint(|$end_tail) { $stop = 1; last }
} elsif $value ~~ $endpoint { $stop = 1; last }
$tail.push($value);
take $value;
}
Expand Down Expand Up @@ -167,7 +174,13 @@ sub SEQUENCE($left, Mu $right, :$exclude_end) {
while 1 {
$tail.munch($tail.elems - $count);
$value := $code(|$tail);
last if $value ~~ $endpoint;
if $end_code_arity > 1 {
$end_tail.munch($tail.elems - $end_code_arity);
last if $endpoint(|$end_tail);
$end_tail.push($value);
} else {
last if $value ~~ $endpoint;
}
$tail.push($value);
take $value;
}
Expand Down

0 comments on commit 6c13c21

Please sign in to comment.