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

Re: reduce metaoperator on an empty list

Thread Previous | Thread Next
From:
Ph. Marek
Date:
June 7, 2005 22:57
Subject:
Re: reduce metaoperator on an empty list
Message ID:
200506080757.27058.philipp.marek@bmlv.gv.at
On Tuesday 07 June 2005 23:41, Luke Palmer wrote:
> On 6/7/05, Larry Wall <larry@wall.org> wrote:
> > Okay, I've made up my mind.  The "err" option is not tenable because
> > it can cloak real exceptions, and having multiple versions of reduce is
> > simply multiplying entities without adding much power.  So let's allow
> > an optional "identvalue" trait on operators.  If it's there, reduce
> > can use it.  If it's not, reduce returns failure on 0 args.  Built-in
> > addition will have an identity value of 0, while multiplication will
> > have an identity value of 1.  String concatenation will have "".
> > We can go as far as having -Inf on [<] and +Inf on [>]
>
> < and > still don't make sense as reduce operators.  Observe the table:
>
>     # of args   |   Return (type)
>         0       |   -Inf
>         1       |   Num  (the argument)
>         2       |   bool
>         ...     |   bool
How about using initvalue twice for empty array, ie. always pad to at least 
two values?

So
 $bool = [<] @empty_array; # is false (-Inf < -Inf)
 $bool = [<=] @empty_array; # is true (-Inf <= -Inf)

Which would make some sort of sense - in an empty array there's no right 
element that's bigger than it's left neighbour ...

And if the case [<] @empty_array should return true it's easy to use ?? ::.


Just my ยค0.02.


Regards,

Phil


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