2003-04-01 12:38:03 -05:00
|
|
|
PEP: 313
|
|
|
|
Title: Adding Roman Numeral Literals to Python
|
2003-04-01 12:41:34 -05:00
|
|
|
Version: $Revision$
|
|
|
|
Last-Modified: $Date$
|
2003-04-01 12:38:03 -05:00
|
|
|
Author: Mike Meyer <mwm@mired.org>
|
2005-06-17 13:33:18 -04:00
|
|
|
Status: Rejected
|
2003-04-01 12:38:03 -05:00
|
|
|
Type: Standards Track
|
2017-01-10 14:30:39 -05:00
|
|
|
Content-Type: text/x-rst
|
2003-04-01 12:38:03 -05:00
|
|
|
Created: 01-Apr-2003
|
|
|
|
Python-Version: 2.4
|
|
|
|
Post-History:
|
|
|
|
|
|
|
|
|
|
|
|
Abstract
|
2017-01-10 14:30:39 -05:00
|
|
|
========
|
|
|
|
|
|
|
|
This PEP (also known as PEP CCCXIII) 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.
|
2003-04-01 12:38:03 -05:00
|
|
|
|
|
|
|
|
2005-06-17 13:33:18 -04:00
|
|
|
BDFL Pronouncement
|
2017-01-10 14:30:39 -05:00
|
|
|
==================
|
2005-06-17 13:33:18 -04:00
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
This PEP is rejected. While the majority of Python users deemed this
|
|
|
|
to be a nice-to-have feature, the community was unable to reach a
|
|
|
|
consensus on whether nine should be represented as IX, the modern
|
|
|
|
form, or VIIII, the classic form. Likewise, no agreement was
|
|
|
|
reached on whether MXM or MCMXC would be considered a well-formed
|
|
|
|
representation of 1990. A vocal minority of users has also requested
|
|
|
|
support for lower-cased numerals for use in (i) powerpoint slides,
|
|
|
|
(ii) academic work, and (iii) Perl documentation.
|
2005-06-17 13:33:18 -04:00
|
|
|
|
2003-04-01 12:38:03 -05:00
|
|
|
|
|
|
|
Rationale
|
2017-01-10 14:30:39 -05:00
|
|
|
=========
|
2003-04-01 12:38:03 -05:00
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
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, Super Bowls 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.
|
2003-04-01 12:38:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
Syntax for Roman literals
|
2017-01-10 14:30:39 -05:00
|
|
|
=========================
|
2003-04-01 12:38:03 -05:00
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
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:
|
2003-04-01 12:38:03 -05:00
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
1. Except as noted below, they must appear in the order M, D, C,
|
2003-04-04 16:19:59 -05:00
|
|
|
L, X, V then I. Each occurrence of each character adds 1000, 500,
|
2003-04-01 12:38:03 -05:00
|
|
|
100, 50, 10, 5 and 1 to the value of the literal, respectively.
|
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
2. Only one D, V or L may appear in any given literal.
|
2003-04-01 12:38:03 -05:00
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
3. At most three each of Is, Xs and Cs may appear consecutively
|
2003-04-04 16:19:59 -05:00
|
|
|
in any given literal.
|
2003-04-01 12:38:03 -05:00
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
4. A single I may appear immediately to the left of the single V,
|
2003-04-01 12:38:03 -05:00
|
|
|
followed by no Is, and adds 4 to the value of the literal.
|
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
5. A single I may likewise appear before the last X, followed by
|
2003-04-01 12:38:03 -05:00
|
|
|
no Is or Vs, and adds 9 to the value.
|
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
6. X is to L and C as I is to V and X, except the values are 40
|
2003-04-01 12:38:03 -05:00
|
|
|
and 90, respectively.
|
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
7. C is to D and M as I is to V and X, except the values are 400
|
2003-04-01 12:38:03 -05:00
|
|
|
and 900, respectively.
|
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
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.
|
2003-04-01 12:38:03 -05:00
|
|
|
|
|
|
|
|
2003-04-04 16:19:59 -05:00
|
|
|
Built-In "roman" Function
|
2017-01-10 14:30:39 -05:00
|
|
|
=========================
|
2003-04-01 12:38:03 -05:00
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
The new built-in 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
|
2022-01-21 06:03:51 -05:00
|
|
|
rational (see :pep:`239`) it will passed through the existing
|
2017-01-10 14:30:39 -05:00
|
|
|
built-in "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
|
2022-01-21 06:03:51 -05:00
|
|
|
(see :pep:`240`) with the integers in the string being Roman
|
2017-01-10 14:30:39 -05:00
|
|
|
numeral literals.
|
2003-04-01 12:38:03 -05:00
|
|
|
|
|
|
|
|
2003-04-04 16:19:59 -05:00
|
|
|
Compatibility Issues
|
2017-01-10 14:30:39 -05:00
|
|
|
====================
|
2003-04-01 12:38:03 -05:00
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
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
|
2022-01-21 06:03:51 -05:00
|
|
|
variable names violate :pep:`8`, the code is already broken, it
|
2017-01-10 14:30:39 -05:00
|
|
|
just wasn't generating exceptions. This proposal corrects that
|
|
|
|
oversight in the language.
|
2003-04-01 12:38:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
Copyright
|
2017-01-10 14:30:39 -05:00
|
|
|
=========
|
|
|
|
|
|
|
|
This document has been placed in the public domain.
|
2003-04-01 12:38:03 -05:00
|
|
|
|
|
|
|
|
2017-01-10 14:30:39 -05:00
|
|
|
..
|
|
|
|
Local Variables:
|
|
|
|
mode: indented-text
|
|
|
|
indent-tabs-mode: nil
|
|
|
|
sentence-end-double-space: t
|
|
|
|
fill-column: 70
|
|
|
|
End:
|