Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
towards @_ support and increasing seqs by default
if the arity of the code for the limit is 0 and the count
is Inf, I try to pass all values so far into the code.

in addition, lists that start with a single number and then
have a limit block will now be increasing, rather than
decreasing (strange to have ... * be increasing and ... * > 5
be decreasing instead)
  • Loading branch information
timo committed Dec 25, 2013
1 parent c248769 commit bc572cd
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/core/operators.pm
Expand Up @@ -86,9 +86,13 @@ 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_code_arity = 0;
my $end_tail := ().list;
$end_code_arity = $endpoint.arity if $endpoint ~~ Code;
if $endpoint ~~ Code {
$end_code_arity = $endpoint.arity;
$end_code_arity = $endpoint.count if $end_code_arity == 0;
$end_code_arity = -Inf if $end_code_arity ~~ Inf;
}

my sub succpred($cmp) {
($cmp < 0) ?? { $^x.succ } !! ( $cmp > 0 ?? { $^x.pred } !! { $^x } )
Expand All @@ -105,10 +109,10 @@ sub SEQUENCE($left, Mu $right, :$exclude_end) {
while @left {
$value = @left.shift;
if $value ~~ Code { $code = $value; last }
if $end_code_arity > 1 {
if $end_code_arity != 0 {
$end_tail.push($value);
if +@$end_tail >= $end_code_arity {
$end_tail.munch($end_tail.elems - $end_code_arity);
$end_tail.munch($end_tail.elems - $end_code_arity) unless $end_code_arity ~~ -Inf;
if $endpoint(|@$end_tail) { $stop = 1; last }
}
} elsif $value ~~ $endpoint { $stop = 1; last }
Expand Down Expand Up @@ -165,7 +169,7 @@ sub SEQUENCE($left, Mu $right, :$exclude_end) {
}
}
elsif $tail.elems == 1 {
$code = $a cmp $endpoint > 0 ?? { $^x.pred } !! { $^x.succ }
$code = ($a cmp $endpoint > 0 || $endpoint ~~ Code)?? { $^x.pred } !! { $^x.succ }
}
elsif $tail.elems == 0 {
$code = {()}
Expand All @@ -176,10 +180,10 @@ sub SEQUENCE($left, Mu $right, :$exclude_end) {
while 1 {
$tail.munch($tail.elems - $count);
$value := $code(|$tail);
if $end_code_arity > 1 {
if $end_code_arity != 0 {
$end_tail.push($value);
unless $end_tail.elems < $end_code_arity {
$end_tail.munch($end_tail.elems - $end_code_arity);
$end_tail.munch($end_tail.elems - $end_code_arity) unless $end_code_arity ~~ -Inf;
last if $endpoint(|@$end_tail);
}
} else {
Expand Down

0 comments on commit bc572cd

Please sign in to comment.