Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Slices on auto-extending arrays now work as lvalue
As per my interpretation of S09:217

my @A;
@A[^Inf] = ^4;    # 0,1,2,3
@A[^4] = ^Inf;    # 0,1,2,3
@A[^Inf] = ^Inf;  # noop
  • Loading branch information
lizmat committed Apr 17, 2015
1 parent c30f235 commit 420a9b5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/array_slice.pm
@@ -1,5 +1,11 @@
# all sub postcircumfix [] candidates here please

sub NPOSITIONS(\pos, \elems) { # generate N positions
my Mu $indexes := nqp::list();
nqp::setelems($indexes,elems);
nqp::bindpos($indexes,$_,pos.AT-POS($_)) for 0..^elems;
$indexes;
}
sub POSITIONS(\SELF, \pos) { # handle possible infinite slices
my $positions := pos.flat;

Expand Down Expand Up @@ -130,10 +136,14 @@ multi sub postcircumfix:<[ ]>( \SELF, Positional:D \pos ) is rw {
?? SELF.AT-POS(pos.Int)
!! POSITIONS(SELF,pos).map({ SELF[$_] }).eager.Parcel;
}
multi sub postcircumfix:<[ ]>( \SELF, Positional:D \pos, Mu \assignee ) is rw {
multi sub postcircumfix:<[ ]>( \SELF, Positional:D \pos, Mu \val ) is rw {
nqp::iscont(pos)
?? SELF.ASSIGN-POS(pos.Int,assignee)
!! POSITIONS(SELF,pos).map({ SELF[$_] }).eager.Parcel = assignee;
?? SELF.ASSIGN-POS(pos.Int,val)
!! pos.?infinite
?? val.?infinite
?? ()
!! (SELF[NPOSITIONS(pos,val.elems)] = val)
!! (POSITIONS(SELF,pos.list).map({SELF[$_]}).eager.Parcel = val);
}
multi sub postcircumfix:<[ ]>(\SELF, Positional:D \pos, :$BIND!) is rw {
X::Bind::Slice.new(type => SELF.WHAT).throw;
Expand Down

0 comments on commit 420a9b5

Please sign in to comment.