Range Operation pre-PEP

Alex Martelli aleaxit at yahoo.com
Fri May 11 18:17:48 EDT 2001


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.989607330.30318.python-list at python.org...
> [Rainer Deyke]
> > I can't think of a single function in the standard library which
> > takes an unbounded number of heterogenous arguments.  I can think
> > of several which take an unbounded number of homogeneous arguments.
> > 'min' and 'max' for example.
>
> ?
>
> >>> import sys
> >>> min(1, 1.0, [1], "one", {1 :1}, sys.stdin)
> 1
> >>>
>
> I suppose those are homogeneous arguments in the sense that they're all
> objects, but if that's the degenerate sense we're using then I don't know
> what heterogeneous could mean.

Isn't it (Python 2.1 at least) "homogeneous in the sense they're all
COMPARABLE"...?  min/max USED TO work on all objects, at least
all built-in ones I think, but no more...:

D:\Python21>python
Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> min(1,'a',2.0,3j)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: cannot compare complex numbers using <, <=, >, >=
>>>

vs the old behavior

D:\Python20>python
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
Alternative ReadLine -- Copyright 2001, Chris Gonnerman
>>> min(1,'a',2.0,3j)
3j
>>>


Python doesn't formally define interfaces/protocols ("yet", he
adds hopefully:-), but "informally" it has them -- here, it seems
to me that the objects min/max accept need to "implement
OrderedComparable" (be adaptable to protocol "compare by
< &c") in the typical informal Python sense of interfaces and
protocols/'implements' and 'adaptable to'...


Alex






More information about the Python-list mailing list