Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
s/Pos/Index/ and make (r)index return Nil on fail
  • Loading branch information
lizmat committed Jul 29, 2015
1 parent c27dc53 commit 98cdc1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions src/core/Any.pm
@@ -1,6 +1,6 @@
my class MapIter { ... }
my class Pair { ... }
my class Pos { ... }
my class Index { ... }
my class Range { ... }
my class X::Adverb::Slice { ... }
my class X::Bind { ... }
Expand Down Expand Up @@ -297,23 +297,23 @@ my class Any { # declared in BOOTSTRAP
self.map: {
$index = $index+1;
next unless .match($test);
nqp::box_i($index,Pos);
nqp::box_i($index,Index);
};
}
multi method grep-index(Callable:D $test) {
my int $index = -1;
self.map: {
$index = $index + 1;
next unless $test($_);
nqp::box_i($index,Pos);
nqp::box_i($index,Index);
};
}
multi method grep-index(Mu $test) {
my int $index = -1;
self.map: {
$index = $index + 1;
next unless $_ ~~ $test;
nqp::box_i($index,Pos);
nqp::box_i($index,Index);
};
}

Expand Down Expand Up @@ -342,23 +342,23 @@ my class Any { # declared in BOOTSTRAP
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Pos) if .match($test);
return nqp::box_i($index,Index) if .match($test);
};
Nil;
}
multi method first-index(Callable:D $test) {
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Pos) if $test($_);
return nqp::box_i($index,Index) if $test($_);
};
Nil;
}
multi method first-index(Mu $test) {
my int $index = -1;
self.map: {
$index = $index + 1;
return nqp::box_i($index,Pos) if $_ ~~ $test;
return nqp::box_i($index,Index) if $_ ~~ $test;
};
Nil;
}
Expand All @@ -374,7 +374,7 @@ my class Any { # declared in BOOTSTRAP
my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Pos) if self.AT-POS($index).match($test);
return nqp::box_i($index,Index) if self.AT-POS($index).match($test);
}
Nil;
}
Expand All @@ -385,7 +385,7 @@ my class Any { # declared in BOOTSTRAP
my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Pos) if $test(self.AT-POS($index));
return nqp::box_i($index,Index) if $test(self.AT-POS($index));
}
Nil;
}
Expand All @@ -396,7 +396,7 @@ my class Any { # declared in BOOTSTRAP
my int $index = $elems;
while $index {
$index = $index - 1;
return nqp::box_i($index,Pos) if self.AT-POS($index) ~~ $test;
return nqp::box_i($index,Index) if self.AT-POS($index) ~~ $test;
}
Nil;
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/Cool.pm
Expand Up @@ -190,7 +190,7 @@ my class Cool { # declared in BOOTSTRAP
nqp::unbox_s($needle.Str),
nqp::unbox_i($pos.Int)
);
$result < 0 ?? Pos !! nqp::box_i($result,Pos);
$result < 0 ?? Nil !! nqp::box_i($result,Index);
}

proto method rindex(|) {*}
Expand All @@ -205,7 +205,7 @@ my class Cool { # declared in BOOTSTRAP
nqp::unbox_s(self.Str),
nqp::unbox_s($needle.Str),
);
$result < 0 ?? Pos !! nqp::box_i($result,Pos);
$result < 0 ?? Nil !! nqp::box_i($result,Index);
}

proto method split(|) {*}
Expand Down Expand Up @@ -272,8 +272,8 @@ my class Cool { # declared in BOOTSTRAP
proto method Int(|) { * }
multi method Int() { self.Numeric.Int }

proto method Pos(|) { * }
multi method Pos() { self.Numeric.Int.Pos }
proto method Index(|) { * }
multi method Index() { self.Numeric.Int.Index }

proto method UInt(|) { * }
multi method UInt() {
Expand Down
10 changes: 5 additions & 5 deletions src/core/Int.pm
Expand Up @@ -28,7 +28,7 @@ my class Int does Real { # declared in BOOTSTRAP
}

method Int() { self }
multi method Pos(Int:D:) { nqp::box_i(nqp::unbox_i(self),Pos) }
multi method Index(Int:D:) { nqp::box_i(nqp::unbox_i(self),Index) }

multi method Str(Int:D:) {
nqp::p6box_s(nqp::tostr_I(self));
Expand Down Expand Up @@ -163,10 +163,10 @@ my class Int does Real { # declared in BOOTSTRAP
}
}

my class Pos is Int {
multi method Bool(Pos:U:) { False };
multi method Bool(Pos:D:) { True };
multi method Int(Pos:D:) { nqp::box_i(nqp::unbox_i(self),Int) }
my class Index is Int {
multi method Bool(Index:U:) { False };
multi method Bool(Index:D:) { True };
multi method Int(Index:D:) { nqp::box_i(nqp::unbox_i(self),Int) }
}

multi sub prefix:<++>(Int:D $a is rw) {
Expand Down

0 comments on commit 98cdc1e

Please sign in to comment.