wscl icon indicating copy to clipboard operation
wscl copied to clipboard

Uppercase vs lowercase for base >10

Open lassik opened this issue 3 years ago • 3 comments

Does the standard say anywhere if hex and other base>10 numbers should be printed using uppercase (as opposed to lowercase) letters? Uppercase seems to be the norm.

lassik avatar Jan 03 '23 14:01 lassik

Yes, the description for DIGIT-CHAR says specifically "If the resulting character is to be an alphabetic[1] character, it will be an uppercase character." There maybe other places also.

yitzchak avatar Jan 03 '23 14:01 yitzchak

Uppercase

Function DIGIT-CHAR (http://clhs.lisp.se/Body/f_digit_.htm#digit-char)

If the resulting character is to be an alphabetic[1] character, it will be an uppercase character.

No opinion

Variable *PRINT-BASE*, *PRINT-RADIX* (http://clhs.lisp.se/Body/v_pr_bas.htm#STprint-baseST)

For radices above 10, letters of the alphabet are used to represent digits above 9.

If the value of print-radix is true, the printer will print a radix specifier to indicate the radix in which it is printing a rational number. The radix specifier is always printed using lowercase letters. If print-base is 2, 8, or 16, then the radix specifier used is #b, #o, or #x, respectively.

2.3.2.1.1 Syntax of an Integer (http://clhs.lisp.se/Body/02_cbaa.htm)

13.1.4.6 Digits in a Radix (http://clhs.lisp.se/Body/13_adf.htm)

22.1.3.1.1 Printing Integers (http://clhs.lisp.se/Body/22_acaa.htm)

22.3.2.1 Tilde R: Radix (http://clhs.lisp.se/Body/22_cba.htm)

22.3.2.5 Tilde X: Hexadecimal (http://clhs.lisp.se/Body/22_cbe.htm)

current output base (http://clhs.lisp.se/Body/26_glo_c.htm#current_output_base)

digit (http://clhs.lisp.se/Body/26_glo_d.htm#digit)

radix (http://clhs.lisp.se/Body/26_glo_r.htm#radix)

lassik avatar Jan 03 '23 15:01 lassik

Note that if you want a specific case, you can use format ~:@( or ~(

cl-user> (format t "~:@(~X~) ~:*~(~X~)~%" #xbabe)
BABE babe
nil

informatimago avatar Jan 03 '23 16:01 informatimago