[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 15:24:19 +0900, scozens@pwj.co.jp wrote:
>>    print @a[1..-2];         # second through third-last
>
>I had something like this working before, but MJD pointed out
>x..y where x>y already has a meaning - it's defined in perlop
>to return an empty list.

Considering these are slice-context sensitive magic for the range
operator, that doesn't seem like a big deal to me, because a
conventional range like (1..-2) would still be the empty list,
and people are unlikely to be relying on something as useless as
generating an empty list with an invalid range.

But breaking code is always a worry, and would be an argument for
new syntax rather than reusing existing syntax.

>>    print @a[..-2];          # first through third-last
>
>Breaking intuition with $a[-1] being the final element
>because...?

No good reason--I probably mistakenly wrote it that way because
of the symmetry.  If I were thinking straight, I'd pick -1 for
the end of the range.

>>    print @a[..];       # everything (useless?)
>
>@a[$x..$y] - who's to say that $x and $y can't be undef oh
>my gosh.

I think undefs should get you 0..0, which would be the first item.

>>    print (1,2,3)[1..-2];    # empty-list/error/reverse(1,2) ???
>
>Uhm. I'd say empty list. Interesting.

OK, now consider lvalue slices. :-)


Sarathy
gsar@ActiveState.com


Follow-Ups from:
Mark-Jason Dominus <mjd@plover.com>
References to:
scozens@pwj.co.jp

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