*print-case*
∗print-case∗ Variable
Value Type:
One of the symbols :upcase, :downcase, or :capitalize.
Initial Value:
The symbol :upcase.
Description:
The value of *print-case* controls the case (upper, lower, or mixed) in which to print any uppercase characters in the names of symbols when vertical-bar syntax is not used.
*print-case* has an effect at all times when the value of *print-escape* is false. *print-case* also has an effect when the value of *print-escape* is true unless inside an escape context (i.e., unless between vertical-bars or after a slash).
Examples:
(defun test-print-case ()
(dolist (\*print-case\* ’(:upcase :downcase :capitalize))
(format t "~&~S ~S~%" ’this-and-that ’|And-something-elSE|)))
→ TEST-PC
;; Although the choice of which characters to escape is specified by
;; \*PRINT-CASE\*, the choice of how to escape those characters
;; (i.e., whether single escapes or multiple escapes are used)
;; is implementation-dependent. The examples here show two of the
;; many valid ways in which escaping might appear.
(test-print-case) ;Implementation A
▷ THIS-AND-THAT |And-something-elSE|
▷ this-and-that a\n\d-\s\o\m\e\t\h\i\n\g-\e\lse
▷ This-And-That A\n\d-\s\o\m\e\t\h\i\n\g-\e\lse
→ NIL
(test-print-case) ;Implementation B
▷ THIS-AND-THAT |And-something-elSE|
▷ this-and-that a|nd-something-el|se
▷ This-And-That A|nd-something-el|se
→ NIL
See Also:
writeNotes:
read normally converts lowercase characters appearing in symbols to corresponding uppercase characters, so that internally print names normally contain only uppercase characters.
If *print-escape* is true, lowercase characters in the name of a symbol are always printed in lowercase, and are preceded by a single escape character or enclosed by multiple escape characters; uppercase characters in the name of a symbol are printed in upper case, in lower case, or in mixed case so as to capitalize words, according to the value of *print-case*. The convention for what constitutes a “word” is the same as for string-capitalize.
Expanded Reference: *print-case*
:upcase (Default)
Symbol names with all uppercase internal characters are printed in uppercase.
(let ((*print-case* :upcase))
(write-to-string 'hello-world))
=> "HELLO-WORLD"
:downcase
Uppercase characters in symbol names are printed in lowercase.
(let ((*print-case* :downcase))
(write-to-string 'hello-world))
=> "hello-world"
(let ((*print-case* :downcase))
(format nil "~S ~S" 'defun 'my-function))
=> "defun my-function"
:capitalize
Each word in the symbol name is capitalized. Words are separated by non-alphanumeric characters.
(let ((*print-case* :capitalize))
(write-to-string 'hello-world))
=> "Hello-World"
(let ((*print-case* :capitalize))
(format nil "~S ~S" 'defun 'my-function))
=> "Defun My-Function"
Effect on Mixed-Case Symbol Names
*print-case* only affects the case of uppercase characters in the internal name. Lowercase characters in symbol names (created with vertical bars or backslash escapes) are always printed in lowercase with appropriate escaping when *print-escape* is true.
(let ((*print-case* :upcase))
(write-to-string '|MixedCase|))
=> "|MixedCase|"
(let ((*print-case* :downcase)
(*print-escape* nil))
(write-to-string 'hello))
=> "hello"