Skip to main content

*print-gensym*

print-gensym∗ Variable

Value Type:

a generalized boolean.

Initial Value:

true.

Description:

Controls whether the prefix “#:” is printed before apparently uninterned symbols. The prefix is printed before such symbols if and only if the value of *print-gensym* is true.

Examples:

(let ((\*print-gensym\* nil)) 
(print (gensym)))
▷ G6040
→ #:G6040

See Also:

write, *print-escape*

print-level, print-length

print-level,

Expanded Reference: *print-gensym*

Default Behavior (true)

When *print-gensym* is true, uninterned symbols are printed with the #: prefix to distinguish them from interned symbols.

(let ((*print-gensym* t))
(write-to-string (make-symbol "FOO")))
=> "#:FOO"

(let ((*print-gensym* t))
(write-to-string (gensym)))
;; => "#:G123"

When Set to NIL

When *print-gensym* is false, uninterned symbols are printed without the #: prefix, making them look like interned symbols.

(let ((*print-gensym* nil))
(write-to-string (make-symbol "FOO")))
=> "FOO"

Impact on Readability

Without the #: prefix, reading the output back would produce an interned symbol rather than an uninterned one, losing the original identity.

(let* ((sym (gensym "TEMP"))
(with-prefix (let ((*print-gensym* t))
(write-to-string sym)))
(without-prefix (let ((*print-gensym* nil))
(write-to-string sym))))
(list with-prefix without-prefix))
;; => ("#:TEMP1" "TEMP1")

print (and prin1) respect the current binding of *print-gensym*.

(let ((*print-gensym* nil))
(prin1-to-string (gensym "X")))
;; => "X1"