Status of PEP's?

Gareth McCaughan Gareth.McCaughan at pobox.com
Thu Feb 28 19:29:56 EST 2002


Samuele Pedroni wrote:
> Maybe this is a useful insight:
> 
> in mathematetics it is not uncommon to
> identify the natural numbers with the set
> of their predecessors
[etc]
> so also the notation   1 in 5  is natural.

I am a mathematician. The areas of mathematics I always
liked best were set theory and number theory (though I
ended up doing my PhD on something else). I am very
familiar with the von Neumann ordinals, which Samuele
describes.

Nevertheless, I think this would be a terrible thing
to put into Python. "Explicit is better than implicit",
remember? It would confuse newbies severely. It would
confuse non-newbies severely too, actually, though I
expect they'd get used to it. (Heck, people get used
to Perl and C++, too.) The "for x in 5" notation seems
to me to have no advantage whatever other than brevity.

von Neumann didn't invent his construction of the ordinals
because it was obviously the right thing, or because it
was natural. He did it because it was simple. When what
you're doing is laying foundations for mathematics,
that counts for a lot. But that's not what Python is about.

Go and look at a set theory textbook that describes that
construction of the natural numbers. It's a good guess that
within a few pages they will also have defined integers
as equivalence classes of ordered pairs of natural numbers,
rationals as equivalence classes of ordered pairs of integers,
and real numbers as Dedekind sections or equivalence classes
of Cauchy sequences or something. Should we take inspiration
from those too? Then, for instance, we could do

    >>> for x in -3:
    ...   print x
    ... 
    (3, 0)
    (4, 1)
    (5, 2)
    [etc, etc, until interrupted]

It doesn't get much more natural than that. :-)
I suppose we might also get

    >>> for x in math.pi:
    ...   print x
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    TypeError: iteration over uncountable set

(My own preferences, not that anyone asked for them:
I always rather liked the range literal proposal, but
GvR rejected that. I also like the "for 3 <= i < 10"
one, which I think is *beautiful* but maybe slightly
too cute.)

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
.sig under construc



More information about the Python-list mailing list