*print-escape*
∗print-escape∗ Variable
Value Type:
a generalized boolean.
Initial Value:
true.
Description:
If false, escape characters and package prefixes are not output when an expression is printed.
If true, an attempt is made to print an expression in such a way that it can be read again to produce an equal expression. (This is only a guideline; not a requirement. See *print-readably*.)
For more specific details of how the value of *print-escape* affects the printing of certain types, see Section 22.1.3 (Default Print-Object Methods).
Examples:
(let ((\*print-escape\* t)) (write #\a))
▷ #\a
→ #\a
(let ((\*print-escape\* nil)) (write #\a))
▷ a
→ #\a
Affected By:
princ, prin1, format
See Also:
write, readtable-case
Notes:
princ effectively binds *print-escape* to false. prin1 effectively binds *print-escape* to true.
Expanded Reference: *print-escape*
Default Behavior (true)
When *print-escape* is true (the default), objects are printed with escape characters so they can be read back by read.
(let ((*print-escape* t))
(write-to-string "hello"))
=> "\"hello\""
(let ((*print-escape* t))
(write-to-string #\Space))
=> "#\\ "
(let ((*print-escape* t))
(write-to-string 'foo))
=> "FOO"
When Set to NIL
When *print-escape* is false, escape characters and package prefixes are omitted. Output looks "nice" but may not be readable by read.
(let ((*print-escape* nil))
(write-to-string "hello"))
=> "hello"
(let ((*print-escape* nil))
(write-to-string #\Space))
=> " "
Relationship to prin1 and princ
prin1 binds *print-escape* to true; princ binds it to false. This is the key difference between the two functions.
;; prin1 uses escape characters
(prin1-to-string "She said \"hi\"")
=> "\"She said \\\"hi\\\"\""
;; princ suppresses escape characters
(princ-to-string "She said \"hi\"")
=> "She said \"hi\""
Effect on Symbols with Special Characters
(let ((*print-escape* t))
(write-to-string '|hello world|))
=> "|hello world|"
(let ((*print-escape* nil))
(write-to-string '|hello world|))
=> "hello world"