Skip to main content

print-not-readable-object

print-not-readable-object Function

Syntax:

print-not-readable-object condition ! object

Arguments and Values:

condition—a condition of type print-not-readable.

object—an object.

Description:

Returns the object that could not be printed readably in the situation represented by condition.

See Also:

print-not-readable, Chapter 9 (Conditions)

Expanded Reference: print-not-readable-object

Retrieving the Unprintable Object

print-not-readable-object takes a condition of type print-not-readable and returns the object that could not be printed readably.

(handler-case
(let ((*print-readably* t))
(write-to-string *standard-output*))
(print-not-readable (c)
(let ((obj (print-not-readable-object c)))
(format nil "Cannot print ~A readably" (type-of obj)))))
;; => "Cannot print SYNONYM-STREAM readably" ; type is implementation-dependent

Using in Error Handling

(handler-case
(let ((*print-readably* t))
(write-to-string (make-hash-table)))
(print-not-readable (c)
(let ((obj (print-not-readable-object c)))
(format nil "Object of type ~S is not printable readably"
(type-of obj)))))
;; => "Object of type HASH-TABLE is not printable readably"
;; Note: SBCL can print hash tables readably using #. syntax

The Object Is the Same Identity

The returned object is the same (by eq) as the object that was being printed when the error was signaled.

(let ((ht (make-hash-table)))
(handler-case
(let ((*print-readably* t))
(write-to-string ht))
(print-not-readable (c)
(eq ht (print-not-readable-object c)))))
;; => T ; SBCL can print hash tables readably, so handler-case is not entered