[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [PATCH 5.005_63] Open-ended slices: (a..z)[23..]
On Mon, Jan 24, 2000 at 10:13:39PM -0800, Gurusamy Sarathy wrote:
> On Tue, 25 Jan 2000 13:32:07 +0900, scozens@pwj.co.jp wrote:
> >Here's a *much* tidied-up version of the open-ended slice patch I've
> >been working on. I've only confined it to lists, since you can use
> >@a[$x..@a] on arrays. I haven't included the new perly.c for the
> >sake of brevity; please make and fix the usual way.
> >You can now finally do things like (split /:/, $_)[2..] to get all
> >but the first two elements and (split /:/, $_)[-2..] to get the last
> >two.
>
> Interesting idea, but I think I'd want it to be more general than
> what you've got there.
I agree. Only allowing open-ended slices on lists and not on arrays is
silly. It should not be added for one unless it is added for both.
Note that an anonymous array might be accessed like this:
@{$x->{key}[0]}[0..4]
In which case accessing the first through last would be:
@{$x->{key}[0]}[0..$#{$x->{key}[0]}]
So if we allow (0,1,2)[0..], then we should also allow @{$x->{key}[0]}[0..].
> The interesting question is what to do with this:
>
> print (1,2,3)[1..-2]; # empty-list/error/reverse(1,2) ???
It will be a compile error, same as it is now. :)
Ronald
- References to:
-
scozens@pwj.co.jp
Gurusamy Sarathy <gsar@ActiveState.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]