[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 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.

Ranges are simply ordinary list expressions currently.  If we start
down the path of giving ranges context sensitive magic, we should
go a little farther for completeness.  I'd simply use negative indices
(conceptual -0 included) to refer to things at the end.  (We'll assume
absense of a number at the beginning stands for 0, and absense of a
number at the end stands for -0.)

    print @a[3..];		# fourth item to the last
    print @a[-2..];		# last three items
    print @a[1..-2];		# second through third-last
    print @a[..-2];		# first through third-last
    print @a[..];		# everything (useless?)

The interesting question is what to do with this:

    print (1,2,3)[1..-2];	# empty-list/error/reverse(1,2) ???


Sarathy
gsar@ActiveState.com


Follow-Ups from:
Jeff Pinyan <jeffp@crusoe.net>
Graham Barr <gbarr@pobox.com>
Ronald J Kimball <rjk@linguist.dartmouth.edu>
References to:
scozens@pwj.co.jp

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]