Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why no negative (auto reversed) ranges?

0 views
Skip to first unread message

TSa

unread,
Mar 20, 2006, 7:26:03 AM3/20/06
to perl6-l...@perl.org
HaloO,

S03 does explicitly disallow auto-reversed ranges.
And I'm not sure if the upto operator has a downto
cousin where ^-4 == (-1, -2, -3, -4) returns a list
that is suitable for indexing an array from the back.
Why is that so?

With negative ranges, negative array and list length
becomes a logical extension and .reverse just flips
the sign of the array. But I know that code snippets
like 'if @array < 10 {...}' then need to be "upgraded"
to explicitly take the abs: 'if abs @array < 10 {...}'
which is good documentation but somewhat inconvenient.
OTOH, using contentless arrays as kind of integer becomes
even more attractive ;)

Is there a .reversed property for arrays, lists and
ranges that allows to query the direction of growth?
And is .reverse working lazily with respect to the
list or array and just flips this property?
--

Larry Wall

unread,
Mar 23, 2006, 11:07:33 AM3/23/06
to perl6-l...@perl.org
On Mon, Mar 20, 2006 at 01:26:03PM +0100, TSa wrote:
: HaloO,

:
: S03 does explicitly disallow auto-reversed ranges.
: And I'm not sure if the upto operator has a downto
: cousin where ^-4 == (-1, -2, -3, -4) returns a list
: that is suitable for indexing an array from the back.
: Why is that so?

I suppose because nobody else wanted it yet. If we were to add
such an operator opposite to ^4, I suspect it'd be v-4 or some such,
but maybe negative version numbers are more useful. :-)

But Huffman coding says that symmetry *should* be broken when a thing
is used much more frequently than its opposite.

: With negative ranges, negative array and list length


: becomes a logical extension and .reverse just flips
: the sign of the array. But I know that code snippets
: like 'if @array < 10 {...}' then need to be "upgraded"
: to explicitly take the abs: 'if abs @array < 10 {...}'
: which is good documentation but somewhat inconvenient.

People would certainly rebel.

: OTOH, using contentless arrays as kind of integer becomes
: even more attractive ;)

Though you can always use $array as an arrayless content...

: Is there a .reversed property for arrays, lists and


: ranges that allows to query the direction of growth?

Not with a standard array.

: And is .reverse working lazily with respect to the


: list or array and just flips this property?

.reverse isn't a mutator. It merely presents a reversed view of
whatever, and is hopefully as lazy as the underlying object allows
in reverse. (To reverse an array in place we'd use .=reverse.)

Larry

0 new messages