[Python-Dev] request for minor enhancement / linear algebra

Greg Wilson gvwilson@nevex.com
Fri, 14 Jul 2000 11:17:17 -0400 (EDT)


> > Greg Wilson wrote:
> > I would like 'min' and 'max' to be in-fix binary operators, with '__min__'
> > and '__max__' as the associated overloadable method names, and 'min=' and
> > 'max=' as the in-place forms.

> On Fri, 14 Jul 2000, Guido van Rossum wrote:
>
> 1. in-fix min and max: you want to write "x min y" instead min(x, y).
> Why?  It's not a notation I'm familiar with.  Plus it's incompatible,
> since min would have to be a reserved word and it would break all
> existing code using min().

I got there by working backwards to make things consistent.  I want
overloadable '__min__' and 'min=', and everything else that has these
forms is binary infix (I think).

> 2. __min__ and __max__ to override the semantics.  Sure, this can be
> added regardless of (1).  But do you want to override min(a, b) or
> min(sequence)?  Note that min() and max() are variadic functions --
> you can write min(a,b,c,d,e) which is the same as min([a,b,c,d,e]).

'+', '*', and the bitwise operators are equally variadic --- is confusion
avoided by using punctuation for the infix binary form, and a named
function for the general form?

If the answer is 'yes', then my crystal ball predicts the following
exchange:

    Greg:    So let's adopt the notation '<?' and '>?' for 'min' and
             'max', as used in C* and other parallel languages.  We can
             then use '<?=' and '>?=' for the infix forms, and reserve
             'min()' and 'max()' as built-ins for the variadic forms.
             After all, it's just an historical accident that 'min' and
             'max' aren't treated with the same respect as '+' and 'or'.

    Someone: Uck! I've never seen that before! It looks like line noise!
             It's not worth complexifying the core language with new
             operators for this special case.

    Greg:    ...which is exactly the response I've twice typed in, and
             deleted, on the "linear algebra operators" thread.  If 'min'
             and 'max' (which are used for strings as well as numbers)
             aren't worth new operators, I don't think matrices are either
             (and I probably do more matrix algebra than most people on
             this list).

> 3. min= and max=?  Ah, I see, like += and -=.  Since I don't see much
> hope for (1) this is irrelevant.  (But it's a good proposal for a
> generic syntax for other operators that are spelled with a reserved
> word.)

Thanks,
Greg

p.s. if min(a,b,c,d,e) is the same as min([a,b,c,d,e]), then what is the
meaning of min([a,b,c,d,e], [g,h,i,j,k])?