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

Re: reduce metaoperator on an empty list

Thread Previous | Thread Next
From:
Stuart Cook
Date:
May 18, 2005 23:16
Subject:
Re: reduce metaoperator on an empty list
Message ID:
49b351060505182316b76a309@mail.gmail.com
On 5/19/05, Brad Bowman <list@bereft.net> wrote:
> Can't the appropriate identity just be prepended?
> 
> > > my @a;
> > > [+] @a; # 0? exception?
> [+] (0, @a);
> 
> > > [*] @a; # 1? exception?
> [*] (1, @a);
> 
> > > [<] @a; # false?
> [<] (-Inf, @a);  # ???

Wow, that's actually pretty elegant, and it has the benefit of
explicitly TELLING the reader what you intended to do.

Another option (depending on your situation) is to use 'err' to
replace the resultant 'undef' with a value of your choosing, i.e.

[*]  @coefficients   err 1;
[+]  @scores         err 0;
[&&] @preconditions  err 1;

etc. (assuming I got the precedence right)

I think all these rather nice workarounds, combined with the hairiness
and complexity of trying to come up with default answers, make a
really strong case for undef/fail being the right choice here.


Stuart

Thread Previous | 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