Future division patch available (PEP 238)
Paul Winkler
paul at calendargalaxy.com
Wed Jul 25 12:31:38 EDT 2001
Christian Tanzer wrote:
> - Just a wild idea: the problem you want to solve is that the existing
> division operator mixes two totally different meanings and thus
> leads to nasty surprises.
>
> What if `/` applied to two integer values returned neither an
> integer nor a float but an object carrying the float result but
> behaving like an integer if used in an integer context?
>
> For instance:
>
> >>> x = 1/2
> >>> type(x)
> <type 'Ratio'>
> >>> print "%d %f %s" % (x, x, x)
> 0 0.5 0.5
> >>> 2 * x
> 0
> >>> 2. * x
> 1.0
Intriguing, but it worries me. You're proposing a behavior for the / operator
where it still produces a different type depending on the operand types, and
this new type behaves differently in different contexts. I think that's just
trading the old can of worms for a (possibly much larger) new can of worms. I
thought the whole point of the PEP was to make division behave consistently -
that is, always return the same type of result regardless of the operands.
--
................... paul winkler ....................
custom calendars & printing: http://www.calendargalaxy.com
A member of ARMS: http://www.reacharms.com
home page: http://www.slinkp.com
More information about the Python-list
mailing list