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

Re: reduce metaoperator on an empty list

Thread Previous | Thread Next
From:
C. Scott Ananian
Date:
May 19, 2005 07:21
Subject:
Re: reduce metaoperator on an empty list
Message ID:
Pine.LNX.4.61.0505191018410.11097@cag.csail.mit.edu
On Wed, 18 May 2005, Rob Kinyon wrote:

> On 5/18/05, Stuart Cook <scook0@gmail.com> wrote:
>> To summarise what I think everyone is saying, []-reducing an empty
>> list yields either:
>>
>> 1) undef (which may or may not contain an exception), or
>> 2) some unit/identity value that is a trait of the operator,
>>
>> depending on whether or not people think (2) is actually a good idea.
>
> I would think that the Principle of Least Surprise points to (1),
> given that the standard explanation of the [+]@x is eval join( '+', @x
> ) ...

I'd say the principle of least surprise points to (1); in the sense that 
$sum = [+] @x; would Just Work, etc.

I also have a vague sense that the 'identity' value for an operator might 
also be useful in other places in the compiler (enabling optimizations, 
etc).  Providing it as a trait means that these 'other things' could work 
even with user-defined operators.  (And leaving the trait undefined gives 
you the behavior (1), if that's what you want.)
  --scott

Albanian LICOZY shotgun CABOUNCE plastique Sigint Justice fissionable 
LITEMPO KGB KUCAGE LIONIZER ESCOBILLA North Korea CLOWER genetic NRA
                          ( http://cscott.net/ )

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