Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Properly implement internals [].exists|delete, according to new semi-…
…spec
  • Loading branch information
lizmat committed Sep 18, 2013
1 parent c2f7f74 commit 6f86684
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
30 changes: 14 additions & 16 deletions src/core/Array.pm
Expand Up @@ -65,24 +65,22 @@ class Array { # declared in BOOTSTRAP
nqp::bindpos(nqp::getattr(self, List, '$!items'), $pos, bindval)
}

method delete(@array is rw: *@indices) {
my $elems = @array.elems;
my @result;
for @indices -> $index {
my $i = $index ~~ Callable
?? $index($elems)
!! +$index;
@result.push(@array[$i]);
undefine @array[$i];
method delete(\pos) {
return Nil if pos < 0;

# next seems unnecessary but handles an obscure
# edge case
if $i == (@array - 1) {
@array.pop;
}
my $value := self.at_pos(pos);
my $items := nqp::getattr(self,List,'$!items');

if pos == self.end {
my $pos = pos;
nqp::pop($items);
nqp::pop($items)
while --$pos >= 0 && nqp::isnull(nqp::atpos($items,$pos));
}
else {
nqp::bindpos($items, pos, nqp::null());
}
@array.pop while ?@array && !defined @array[@array.elems - 1];
return @result;
$value;
}

method flattens() { 1 }
Expand Down
4 changes: 2 additions & 2 deletions src/core/List.pm
Expand Up @@ -96,9 +96,9 @@ my class List does Positional { # declared in BOOTSTRAP
}

method exists(\pos) {
return False unless self.DEFINITE;
return False if !self.DEFINITE || pos < 0;
self.gimme(pos + 1);
nqp::p6bool(nqp::existspos($!items, nqp::unbox_i(pos)))
nqp::p6bool( !nqp::isnull(nqp::atpos($!items, nqp::unbox_i(pos))) );
}

method gimme($n, :$sink) {
Expand Down

0 comments on commit 6f86684

Please sign in to comment.