develooper Front page | perl.perl6.language | Postings from September 2008

Re: Split with negative limits, and other weirdnesses

Mark J. Reed
September 28, 2008 12:44
Re: Split with negative limits, and other weirdnesses
Message ID:
On Sun, Sep 28, 2008 at 11:40 AM, Chris Davaz <> wrote:
> Ok, so 0 returns the empty list and -1 violates the signature? In PIR
> can we have such signatures that put a constraint on the range of
> values for a given parameter?

Maybe this has already been proposed and rejected, but why not simply
define the limit parameter such that

split($pat, $src, $limit)

is equivalent, result-wise, to

split($pat, $src)[0 .. $limit - 1]

?  Of course, the limit-parameter case might be able to avoid some
work compared to the second, which might not always be able to do its
job lazily, but the return value would be the same.  Then you don't
have to come up with separate edge case rules for two different
constructs... the one follows logically from the other.

$limit is 0?  @foo[0..-1] is the empty list. Check.

@foo[0..-2] is also the empty list.  So negative parameters don't need to Fail..

Mark J. Reed <> Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About