added PEP 313, Adding Roman Numeral Literals to Python, by Mike Meyer

This commit is contained in:
David Goodger 2003-04-01 17:38:03 +00:00
parent 61029fe234
commit e564707d7a
2 changed files with 118 additions and 0 deletions

View File

@ -114,6 +114,7 @@ Index by Category
S 310 Reliable Acquisition/Release Pairs Hudson, Moore
S 311 Simplified GIL Acquisition for Extensions Hammond
S 312 Simple Implicit Lambda Suzi, Martelli
S 313 Adding Roman Numeral Literals to Python Meyer
Finished PEPs (done, implemented in CVS)
@ -316,6 +317,7 @@ Numerical Index
S 310 Reliable Acquisition/Release Pairs Hudson, Moore
S 311 Simplified GIL Acquisition for Extensions Hammond
S 312 Simple Implicit Lambda Suzi, Martelli
S 313 Adding Roman Numeral Literals to Python Meyer
SR 666 Reject Foolish Indentation Creighton
@ -375,6 +377,7 @@ Owners
McMillan, Gordon gmcm@hypernet.com
McNamara, Andrew andrewm@object-craft.com.au
Mick, Trent trentm@activestate.com
Meyer, Mike mwm@mired.org
Montanaro, Skip skip@pobox.com
Moore, Paul gustav@morpheus.demon.co.uk
Norwitz, Neal neal@metaslash.com

115
pep-0313.txt Normal file
View File

@ -0,0 +1,115 @@
PEP: 313
Title: Adding Roman Numeral Literals to Python
Version: $Revision $
Last-Modified: $Date $
Author: Mike Meyer <mwm@mired.org>
Status: Draft
Type: Standards Track
Content-Type: text/plain
Created: 01-Apr-2003
Python-Version: 2.4
Post-History:
Abstract
This PEP proposes adding Roman numerals as a literal type. It
also proposes the new built-in function "roman", which converts an
object to an integer, then converts the integer to a string that
is the Roman numeral literal equivalent to the integer.
Rationale
Roman numerals are used in a number of areas, and adding them to
Python as literals would make computations in those areas easier.
For instance, Superbowls are counted with Roman numerals, and many
older movies have copyright dates in Roman numerals. Further,
LISP provides a Roman numerals literal package, so adding Roman
numerals to Python will help ease the LISP-envy sometimes seen in
comp.lang.python. Besides, the author thinks this is the easiest
way to get his name on a PEP.
Syntax for Roman literals
Roman numeral literals will consist of the characters M, D, C, L,
X, V and I, and only those characters. They must be in upper
case, and represent an integer with the following rules:
1. Except as noted below, they must appear in the order M, D, C,
L, X, V then I. Each occurence of each character adds 1000, 500,
100, 50, 10, 5 and 1 to the value of the literal, respectively.
2. Only one D, V or L may appear in any given literal.
3. At most three Is, Xs and Cs may appear in any given literal.
4. A single I may appear immediately to the left of the single V,
followed by no Is, and adds 4 to the value of the literal.
5. A single I may likewise appear before the last X, followed by
no Is or Vs, and adds 9 to the value.
6. X is to L and C as I is to V and X, except the values are 40
and 90, respectively.
7. C is to D and M as I is to V and X, except the values are 400
and 900, respectively.
Any literal composed entirely of M, D, C, L, X, V and I characters
that does not follow this format will raise a syntax error,
because explicit is better than implicit.
Builtin "roman" Function
The new builtin function "roman" will aide the translation from
integers to Roman numeral literals. It will accept a single
object as an argument, and return a string containing the literal
of the same value. If the argument is not an integer or a
rational (see PEP 239 [1]) it will passed through the existing
builtin "int" to obtain the value. This may cause a loss of
information if the object was a float. If the object is a
rational, then the result will be formatted as a rational literal
(see PEP 240 [2]) with the integers in the string being Roman
numeral literals.
Compatability Issues
No new keywords are introduced by this proposal. Programs that
use variable names that are all upper case and contain only the
characters M, D, C, L, X, V and I will be affected by the new
literals. These programs will now have syntax errors when those
variables are assigned, and either syntax errors or subtle bugs
when those variables are referenced in expressions. Since such
variable names violate PEP 8 [3], the code is already broken, it
just wasn't generating exceptions. This proposal corrects that
oversight in the language.
References
[1] PEP 239, Adding a Rational Type to Python
http://www.python.org/peps/pep-0239.html
[2] PEP 240, Adding a Rational Literal to Python
http://www.python.org/peps/pep-0240.html
[3] PEP 8, Style Guide for Python Code
http://www.python.org/peps/pep-0008.html
Copyright
This document has been placed in the public domain.
^L
Local Variables:
mode: indented-text
indent-tabs-mode: nil
sentence-end-double-space: t
fill-column: 70
End: