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

Re: reduce metaoperator on an empty list

Thread Previous
Rod Adams
May 18, 2005 18:13
Re: reduce metaoperator on an empty list
Message ID:
Matt Fowles wrote:

>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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About