Skip to content

Commit

Permalink
Give push and unshift "single item" semantics.
Browse files Browse the repository at this point in the history
To patch array assignment, [...], etc.
  • Loading branch information
jnthn committed Aug 13, 2015
1 parent 7d55b06 commit b3c3c78
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/core/Array.pm
Expand Up @@ -184,8 +184,8 @@ my class Array { # declared in BOOTSTRAP
#}

multi method push(Array:D: \value) {
self!ensure-allocated();
if nqp::iscont(value) || nqp::not_i(nqp::istype(value, Iterable)) {
self!ensure-allocated();
my $todo := nqp::getattr(self, List, '$!todo');
if $todo.DEFINITE {
$todo.reify-until-lazy();
Expand All @@ -200,11 +200,14 @@ my class Array { # declared in BOOTSTRAP
self
}
else {
callsame();
self!push-list(value.list)
}
}
multi method push(Array:D: **@values) {
multi method push(Array:D: **@values is rw) {
self!ensure-allocated();
self!push-list(@values)
}
method !push-list(@values) {
my $todo := nqp::getattr(self, List, '$!todo');
if $todo.DEFINITE {
$todo.reify-until-lazy();
Expand Down Expand Up @@ -237,19 +240,21 @@ my class Array { # declared in BOOTSTRAP
self
}
else {
callsame();
self!unshift-list(value.list)
}
}
# XXX GLR
#multi method unshift(Array:D: *@values) {
multi method unshift(Array:D: **@values is rw) {
self!unshift-list(@values)
}
method !unshift-list(@values) {
# XXX GLR
nqp::die('multi-item unshift NYI');
# fail X::Cannot::Infinite.new(:action<push>, :what(self.^name))
# if @values.infinite;
# nqp::p6listitems(self);
# my $elems = self.gimme(*);
# fail X::Cannot::Infinite.new(:action('.push to'))
# if self.infinite;
#
# # push is always eager
# # unshift is always eager
# @values.gimme(*);
#
# self.gimme(*);
Expand All @@ -261,7 +266,7 @@ my class Array { # declared in BOOTSTRAP
# }
#
# self;
#}
}

method pop(Array:D:) is parcel is nodal {
self!ensure-allocated();
Expand Down

0 comments on commit b3c3c78

Please sign in to comment.