Skip to content

Instantly share code, notes, and snippets.

@moritz
Created November 2, 2011 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/1334853 to your computer and use it in GitHub Desktop.
Save moritz/1334853 to your computer and use it in GitHub Desktop.
Initial splice implementation for nom
use MONKEY_TYPING;
augment class List {
method splice($offset = 0, $length = self.elems - $offset, *@rep) {
self.gimme($offset + $length);
@rep.gimme(*);
my @res = self[$offset ... $offset + $length - 1];
pir::splice__vPPII(
$!items,
nqp::getattr(@rep, List, '$!items'),
nqp::unbox_i($offset.Int),
nqp::unbox_i($length.Int)
);
self;
@res;
}
}
my @x = (1, 2, 3);
say @x.splice(1, 1, 'a', 'b', 'c').perl;
say @x.perl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment