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

Re: Split with negative limits, and other weirdnesses

From:
Mark J. Reed
Date:
September 28, 2008 12:44
Subject:
Re: Split with negative limits, and other weirdnesses
Message ID:
f60fe000809281244x5a99b083te1b36d111fb7298f@mail.gmail.com
On Sun, Sep 28, 2008 at 11:40 AM, Chris Davaz <cdavaz@gmail.com> 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 <markjreed@gmail.com>



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