A modest PEP0238 suggestion

Paul Svensson paul at svensson.org
Tue Jul 24 12:56:48 CEST 2001


matthew.feinstein at jhuapl.edu (Matt Feinstein) writes:

>Why not make the operator // do what the -old- division operator did,
>so that the only change that has to be made for backwards
>compatibility is replace all /'s with //'s?

For ever problem, there exists a solution that is simple, obvious, and wrong.

----------------------------------------------------------------------------
	int/int -> int		int/int -> flt		int/int -> int
	flt/flt -> flt		flt/flt -> flt		flt/flt -> int
----------------------------------------------------------------------------
2.1	x/y			(x + 0.0)/y		divmod(x, y)[0]
0238	(don't do that)		x/y			x//y
Matt	x//y			x/y			divmod(x, y)[0]
Others	x/y			x//y			divmod(x, y)[0]
:-)	x/y			x//y			x///y
----------------------------------------------------------------------------

If you read the above table carefully, you'll see one thing that makes the
PEP-0238 solution different from all the others, and I think that's how
Guido intended it.  The problem is not as much that we need to *add* new
stuff to spell out different ways of dividing, but that we need to *remove*
the confusing semantics of the current spelling.  Suggesting alternatives
that don't solve this part of the problem, IMNSHO, totally pointless.

The only choices that make sense to me here are, either we break stuff,
or we do nothing.  Either way, we'll most likely have to revisit the
issue if/when syntax for rationals is to be added to the language.

	/Paul



More information about the Python-list mailing list