develooper Front page | perl.perl6.language | Postings from May 2005

Re: reduce metaoperator on an empty list

Thread Previous
From:
Rod Adams
Date:
May 18, 2005 18:13
Subject:
Re: reduce metaoperator on an empty list
Message ID:
428BE815.8040607@rodadams.net
Matt Fowles wrote:

>All~
>
>What does the reduce metaoperator do with an empty list?
>
>my @a;
>[+] @a; # 0? exception?
>[*] @a; # 1? exception?
>[<] @a; # false?
>[||] @a; # false?
>[&&] @a; # true?
>
>Also if it magically supplies some correct like the above, how does it
>know what that value is?
>  
>

My general thoughts has been that:

    [op] @list

behaves something like:

    eval join(op, @list)

so feeding it an empty list would return undef, regardless of op. 
Similarly, if @list is just one element, it returns that element.

-- Rod Adams




Thread Previous


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