Issue FORMAT-RADIX-MISSING-RADIX
Issue: FORMAT-RADIX-MISSING-RADIX

Forum: Editorial

References: Tilde R: Radix

Category: CLARIFICATION/CHANGE

Edit history: 2004-08-27, Version 1 by Paul Dietz; 2004-08-31, version 2 by Bruno Haible, renamed CLARIFY to DEFAULT-IS-PRINT-BASE, added proposal DEFAULT-IS-ENGLISH-OR-ROMAN

Status: For CLiki consideration

Problem Description:

CLHS does not specify what happens to the ~R directive when the first format parameter (the radix) is missing, but other format parameters are not missing. Also, a strict reading of the standard implies that ~VR means the same as ~R when the V parameter is NIL, which may not be what was intended.

Proposal (FORMAT-RADIX-MISSING-RADIX:DEFAULT-IS-PRINT-BASE):

Change the behavior of Tilde R: Radix so that (1) if any parameter characters (including #\V, #\v, #\#, #\, and digit or comma format parameters) are present before the r (or R), then the special cases for ordinal/cardinal/roman/old roman modes do not occur), and (2) if, in these cases, the first parameter is missing, then the radix defaults to the value of *PRINT-BASE*.

Test cases:

(format nil "~vr" nil 5) ==> "5"
(format nil "~,r" 4) ==> "4"
(let ((*print-base* 8)) (format nil "~,r" 8)) ==> "10"

Rationale:

The special case behavior is an odd overloading of the R directive. The behavior when the radix is not included is currently unspecified; using the printer control variable seems a logical extension.

Proposal (FORMAT-RADIX-MISSING-RADIX:DEFAULT-IS-ENGLISH-OR-ROMAN):

Change the behavior of Tilde R: Radix so that if the first parameter is missing or nil, the cardinal/ordinal/roman/old roman mode is used.

Test cases:

(format nil "~vr" nil 5) ==> "five"
(format nil "~,r" 4) ==> "four"
(let ((*print-base* 8)) (format nil "~,r" 8)) ==> "eight"

Rationale:

The interpretation of a nil parameter as equivalent to a missing parameter is consistent with 22.3 Formatted Output, which states "If the arg used by a V parameter is nil, the effect is as if the parameter had been omitted." Also, proposal DEFAULT-IS-PRINT-BASE has the flaw that it makes it impossible to use FORMAT to print a number in cardinal/ordinal/roman/old roman mode with padding; but padding is otherwise universally available to most FORMAT directives.

Current practice:

CLISP implements proposal DEFAULT-IS-ENGLISH-OR-ROMAN.

Cost to Implementors:

Some avoid having to reimplement ~vr.

Cost to Users:

None.

Cost of Non-Adoption:

More complicated and nonintuitive behavior.

Benefits:

Aesthetics:

Discussion:

  • Bruno Haible supports DEFAULT-IS-ENGLISH-OR-ROMAN.