Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Array.pm to the prelude. For now it just contains splice, written…
… by cspencer++ and attached to RT#49173. Happily, this gets two more of the 99 problems spectests running.
  • Loading branch information
jnthn committed Feb 18, 2009
1 parent d3cc978 commit 444a4c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -106,6 +106,7 @@ BUILTINS_PIR = \
src/builtins/traits.pir \

SETTING = \
src/setting/Array.pm \
src/setting/Bool.pm \
src/setting/List.pm \
src/setting/Pair.pm \
Expand Down
16 changes: 16 additions & 0 deletions src/setting/Array.pm
@@ -0,0 +1,16 @@
class Array is also {
multi method splice(@array is rw: Int $offset = 0, Int $size = @array.elems - $offset, *@values) is export {
my @spliced;
my @deleted;

my $off = ($offset > @array.end) ?? @array.end !! $offset;
my $len = $size;
@spliced.push(@array.shift) while ($off-- > 0 && @array);
@deleted.push(@array.shift) while ($len-- > 0 && @array);
@spliced.push(@values) if @values;
@spliced.push(@array) if @array;

@array = @spliced;
return @deleted;
}
}

0 comments on commit 444a4c8

Please sign in to comment.