Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement splice(); run S32-array/splice.t
  • Loading branch information
Tadeusz Sośnierz committed Nov 2, 2011
1 parent aecd2fc commit b441203
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/core/List.pm
Expand Up @@ -206,6 +206,17 @@ my class List does Positional {
self
}

method splice($offset is copy = 0, $size? is copy, *@values) {
$offset += self.elems if ($offset < 0);
$size //= self.elems - $offset;
$size = self.elems + $size - $offset if ($size < 0);
my @ret = self[$offset..($offset + $size - 1)];
nqp::splice($!items,
nqp::getattr(@values.eager, List, '$!items'),
$offset, $size);
@ret;
}

method sort($by = &infix:<cmp>) {
# We defer to Parrot's ResizablePMCArray.sort method here.
# Instead of sorting elements directly, we sort a Parcel of
Expand Down Expand Up @@ -353,3 +364,6 @@ sub reverse(*@a) { @a.reverse }
sub rotate(@a, Int $n = 1) { @a.rotate($n) }
sub reduce (&with, *@list) { @list.reduce(&with) }
sub categorize(&mapper, *@a){ @a.categorize(&mapper)}
sub splice(@arr, $offset = 0, $size?, *@values) {
@arr.splice($offset, $size, @values)
}
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -493,7 +493,7 @@ S32-array/pop.t
S32-array/push.t
S32-array/rotate.t
S32-array/shift.t
# S32-array/splice.t # err: Undefined routine '&splice' called
S32-array/splice.t
S32-array/unshift.t
S32-basics/warn.t
# S32-container/zip.t # err: Undefined routine '&Seq' called
Expand Down

0 comments on commit b441203

Please sign in to comment.