Initial splice implementation for nom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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