Skip to main content

print-not-readable

print-not-readable Condition Type

Class Precedence List:

print-not-readable, error, serious-condition, condition, t

Description:

The type print-not-readable consists of error conditions that occur during output while *print-readably* is true, as a result of attempting to write a printed representation with the Lisp printer that would not be correctly read back with the Lisp reader . The object which could not be printed is initialized by the :object initialization argument to make-condition, and is accessed by the function print-not-readable-object.

See Also:

print-not-readable-object

Expanded Reference: print-not-readable

What Triggers print-not-readable

The print-not-readable condition is signaled when *print-readably* is true and the printer encounters an object it cannot print in a readable form.

(handler-case
(let ((*print-readably* t))
(write-to-string *standard-output*))
(print-not-readable (c)
(format nil "Caught: ~A" c)))
;; => "Caught: ..." ; implementation-dependent message

Condition Hierarchy

print-not-readable is a subtype of error, which is a subtype of serious-condition.

(subtypep 'print-not-readable 'error)
=> T
=> T

(subtypep 'print-not-readable 'serious-condition)
=> T
=> T

The Offending Object

The object that could not be printed readably can be retrieved using print-not-readable-object.

(handler-case
(let ((*print-readably* t))
(write-to-string (make-hash-table)))
(print-not-readable (c)
(type-of (print-not-readable-object c))))
;; => HASH-TABLE ; SBCL can print hash tables readably

When *print-readably* is true, print-unreadable-object signals print-not-readable rather than printing the #<...> syntax.

(defclass opaque-thing () ())

(defmethod print-object ((obj opaque-thing) stream)
(print-unreadable-object (obj stream :type t)))

(handler-case
(let ((*print-readably* t))
(prin1-to-string (make-instance 'opaque-thing)))
(print-not-readable () "not readable"))
=> "not readable"