my @a = (1,2,3);
my @b = @a[0..3];
print scalar(@b); # 4
But in Perl 6:
my @a = (1,2,3,4);
my @b = @a[1...]; # elements from 1 onward
say +@b; # should probably be 3, but with Perl 5 semantics is Inf
We have to break one of these. I think the former is the one to break,
even though that might cause some unexpected surprises here and there.
Any ideas?
Luke
In Pugs (r1847), after the IType refactoring, I have allowed
infinite slicing of arrays to simply mean "slice until the end".
That is:
@b = @a[1...]; # elements from 1 onward
@b = @a[1..Inf]; # same thing
I think that's far more more intuitive and convenient.
Thanks,
/Autrijus/
I was thinking about this today, actually, because my CS textbook was
talking about multidimensional arrays. If we make an infinite index
mean "slice until you can slice no more", then we can possibly have a
C<term:<*>> which is the same as C<0...>. That means we can slice
like this:
@foo[1,3; *; 7]
Which I rather like. (Although term:<*> might conflict with
prefix:<*>...hmm. I'm not sure it would in common usage--the only
things I can think of that could follow are a dot, opening or closing
bracket, semicolon or comma, or hyperoperator, none of which are
ambiguous if we stick to the no-whitespace-before-postcircumfix rule.)
By the way, this also shortens the common idiom:
@foo[3..@foo.end]
To simply:
@foo[3...]
Which strikes me as a win.
--
Brent 'Dax' Royal-Gordon <br...@brentdax.com>
Perl and Parrot hacker
"I used to have a life, but I liked mail-reading so much better."
Me too. Unless my memory is failing me, I believe that's what S09
already specifies.
Larry
It does include a C<term:<*>> (d'oh, should've checked), but it
doesn't specify how it works.