develooper Front page | perl.perl6.language | Postings from March 2006

why no negative (auto reversed) ranges?

Thread Next
From:
TSa
Date:
March 20, 2006 04:26
Subject:
why no negative (auto reversed) ranges?
Message ID:
441E9F5B.50704@orthogon.com
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?
-- 

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About