[Python-Dev] Re: PEP239 (Rational Numbers) Reference Implementation and new issues

François Pinard pinard@iro.umontreal.ca
Thu, 03 Oct 2002 20:19:36 -0400


[Greg Ewing]

> Maybe there should be a separate operator for rational
> division?
>
>   1/3 --> float
>   1//3 --> int
>   1///3 --> rational
>
> (Okay, a 3-char operator is a bit verbose, but I can't
> think of anything else that looks division-like just at
> the moment.)

I much like Emacs Calc usage of 3:2 or 1:1:2 (no embedded space) for a
fraction constant, read or printed.  I find this more legible and
comfortable to read than 3/2 or `1 1/2'.  There is a Calc setting to decide
if division generates floats or fractions, but Guido is probably right in
choosing that `/' should not be magical enough to produce rationals.

One might presume that introducing `:' between numbers at the syntactic
level has just no chance to ever work.  But _maybe_ it could be more
tractable at the lexical level without bringing too much confusion, and for
numerical _constants_ only -- 3:2 is one number, has never been two.

Rationals could be got through a cast or constructor, or by introducing
rational objects into the computation, like rational constants would be.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard