Comment on PEP-0238

Robert J. Harrison rjh at 3-cities.com
Thu Jul 5 13:05:38 EDT 2001


Paul Prescod wrote:
> > Python extensively distinguishes between numeric
> > types and other types.
> 
> That's my *exact* point. Python strongly enforces the view that there
> are "numbers", "strings".... not "integers", "floats", "strings"
> Integers and floats are strongly related. Much more so than other types.
> 
> No, I do not want to change the behaviour of either of these lines. I'm
> making the point that a threshold has been crossed. The distinction
> between integers and floats has been blurred. The logical conclusion is
> to treat integers as a special case of floats everywhere.

I think a better analogy is between the number property and the 
sequence property. 

   - numbers - integers, longs, floats, complex (with perhaps kinds
     and rationals to be added)

   - sequences - strings, lists, tuples, ...

A number is not a single type because it has properties
such as range and precision associated with it.

For instance, when operating on longs such that the result is too
big to store in a float, the new semantics for divide must
generate a Range or Value error - unless rationals are accepted
into the core language (and I don't want to open that can of
worms here).  The current behaviour has no such problem since
it does not involve any automatic type coercion.  So, again, the
problem does not go away, it has just been moved.  

This also demonstrates that the new PEP does need a special
function or operator to perform closed integer division,
but not for the reasons it cites.
So, a comment I made earlier in this thread (that Guido
agreed with) about preferring use of int(a/b) instead of
a//b, is incomplete.  You cannot compute the integer division
in this fashion for longs without rationals being in the
core.  Since I have not thought about that issue much at
all, I'm left having to choose either // or a function
div(a,b) that does closed integer divide

Uniting ints with floats is entirely workable, but as you
see from above it cannot be done uniformly for all integers 
without extending float to include rationals.  The
consequences and design of this PEP (and all of the other
numeric proposals) need to be much more thought through 
before accepting them.   And we must analyze them all together
rather than just this one alone.  So perhaps it is time
for a new thread.

-- 
Robert J. Harrison (rjh at 3-cities.com)



More information about the Python-list mailing list