Digit separators
Under construction.
Digit
grouping,
Digit separators
ADA,
Java
SE 7, Ruby
Motivation
- Permit to write very large integers in source code with line
width limit
- Enable multi-line/multi-page integers
- Enable tracers to write out large integers
- Make larger integers more readable
- Avoid ad hoc formats
Definition
Replace the syntax productions for integer constant, binary constant,
octal constant and hexadecimal constant.
integer constant (* 6.4.4 *)
= decimal digit char (* 6.5.2 *),
{ [ digit separator (* 6.4.4 *) ] ,
decimal digit char (* 6.5.2 *) } ;
binary constant (* 6.4.4 *)
= binary constant indicator (* 6.4.4 *),
binary digit char (* 6.5.2 *),
{ [ digit separator (* 6.4.4 *) ] ,
binary digit char (* 6.5.2 *) } ;
octal constant (* 6.4.4 *)
= octal constant indicator (* 6.4.4 *),
octal digit char (* 6.5.2 *),
{ [ digit separator (* 6.4.4 *) ] ,
octal digit char (* 6.5.2 *) } ;
hexadecimal constant (* 6.4.4 *)
= hexadecimal constant indicator (* 6.4.4 *),
hexadecimal digit char (* 6.5.2 *),
{ [ digit separator (* 6.4.4 *) ] ,
hexadecimal digit char (* 6.5.2 *) } ;
digit separator (* 6.4.4 *)
= underscore char (* 6.5.2 *),
[ layout text sequence (* 6.4.1 *) ] ;
Options
- single underscore
1_000
(accepted)
- multiple underscores
1__000_000
(undecided)
- followed by layout chars
1_ 000
(accepted)
- followed by layout text
1_ /* comment */ 000
(accepted)
single space for decimals (octal, binary) ISO 31-0 3.3, 80000-1:2009,2022 7.2.1 (rejected)
multiple spaces for decimals (octal,binary) (rejected)
layout chars for decimals (octal, binary) (rejected)
- write options?
History
2010-11-19 pllib Draft 8 added in
6. Numbers as 6.0 Syntax (digit separator
problematic):
digit separator =
underscore char, [new line char, {layout char}];
2013-01-23 Discussion on SWI list "format/2 Thousands separator"
2013-0?-?? SWI includes 1,3,4,5
2013-05-21 Added to main page (check-in 2013-07-11 as 1.11)
digit separator
= underscore char (* 6.5.2 *),
[ layout text sequence (* 6.4.1 *) ] ;
Additionally exactly one space for integer, binary, and octal constant.
2013-12-20 pllib Draft 18 changed to
digit separator =
underscore char, {layout char}, [new line char, {layout char}];
Note that this uses {layout char}
, not [layout text sequence]
. This is deliberate; comments are not allowed inside numbers.
2021-11-27 Scryer 1,3,4 but only decimals (#994,#1112)
2021-06-28 Trealla include 1
2021-08-18 Trealla include 5
2025-04-24 Trealla 1,3,4
2025-06-02 WG17 rejects 5,6,7; accepts 1,3,4