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

Re: reduce metaoperator on an empty list

Thread Previous | Thread Next
From:
Dave Whipp
Date:
June 1, 2005 09:24
Subject:
Re: reduce metaoperator on an empty list
Message ID:
20050601162425.22181.qmail@lists.develooper.com
Luke Palmer wrote:

> For something like:
> 
>     $ordered = [<] @array;
> 
> If @array is empty, is $ordered supposed to be true or false?   It
> certainly shouldn't be anything but those two, because < is a boolean
> operator.

I have no problem with 3-state logic systems (true, false, undef) if 
this is what is required to let me choose the corner-case behavior.

Damian previously wrote:
 > 2+ args: interpolate specified operator
 > 1 arg:   return that arg
 > 0 args:  fail (thrown or unthrown exception depending on use fatal)

The 1-arg case doesn't seem to work right with the [<] operator:

   ? [<] 1
   ? [<] 0

If the [<] is taken to mean "ordered", then it doesn't seem right that 
these two tests would give different results. In this case, I need to 
special case both the 0-arg and 1-arg scenarios. We either need to hard 
code these special-cases into perl (belch), or we need to make it easy 
to code both special-cases inline in the code, or we need a better 
general-case rule.

One approach might be to reverse the direction of the definitions. That 
is, instead of defining the binary form and then autogeneralizing in 
terms of "join", we might define operators in terms of thier reduction 
behavior, and then autospecialize to the binary case. Of course, that 
still doesn't help for Damian's "product Vs factorial" example for the 
0-arg case.

Or we take the well trodden road of ignoring mathematical correctness 
and simply state "this is what perl does: take it or leave it".

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