[Python-Dev] Integer division transition
Mon, 6 Nov 2000 10:05:12 +0100 (MET)
> David Scherer proposed to spell this pragma as a "magical import"
Huh? AFAIR David Scherer and Bruce Sherwood used the 'global'-statement
at module level as a backward compatible method to introduce module level
I still like David Scherers proposal very much.
> I actually implemented 1/2==0.5 in Python 1.5.2, complete with a
> module-level backward compatibility flag. The flag made an unusual use of
> the "global" statement, which appears to be accepted at toplevel by 1.5.2
> without any effect. Therefore a statement like "global olddivision" will be
> silently ignored by 1.5.2 and earlier, and will result in the old behavior
> under my patch. "global" even has the right sort of sound for module-level
> options :)
> An outline of what I did:
> 1. Add new opcode BINARY_FRACTION to opcode.h and dis.py
> 2. Add new flag "int c_olddivision" to struct compiling in compile.c
> 3. Set c_olddivision to base->c_olddivision or 0 in jcompile
> 4. Check for "global olddivision" outside a function definition in
> com_global_stmt, and set c_olddivision=1
> 5. Check c_olddivision in com_term, and generate either BINARY_DIVISION or
> 6. Add PyNumber_Fraction to abstract.h, and define it in abstract.c to
> explicitly check for a pair of integers and do float division
> 7. Add a BINARY_FRACTION case to ceval.c, which calls PyNumber_Fraction
> instead of PyNumber_Divide.
BTW: I think the "symbol" '//' is incredible ugly and starting with
IBMs JCL years ago all languages I encountered, that used this symbol
for something, did suck in some way or another. I would appreaciate
very much, if it could be avoided alltogether to add a symbol '//'
to Python. '//' will look like a comment delimiter to most people today.
Using a new keyword like 'div' in the tradition of languages like
Modula-2 looks far more attractive to me.
Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260
office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)