define SB-EXT:PRINT-UNREADABLY as a function
authorNikodemus Siivola <nikodemus@random-state.net>
Fri, 2 Dec 2011 11:18:00 +0000 (13:18 +0200)
committerNikodemus Siivola <nikodemus@random-state.net>
Mon, 5 Dec 2011 10:16:19 +0000 (12:16 +0200)
  So

    (handler-bind ((print-not-readable #'print-unreadably))
       ...)

  works.

NEWS
src/code/condition.lisp
tests/print.impure.lisp

diff --git a/NEWS b/NEWS
index 99a266b..5cea3b8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ changes relative to sbcl-1.0.54:
        full-blows cross-compilation.)
   * enhancement: MAKE-ALIEN signals a storage-condition instead of returning a
     null alien when malloc() fails. (lp#891268)
+  * enhancement: SB-EXT:PRINT-UNREADABLY restart for PRINT-NOT-READABLE
+    conditions can be conveniently accessed through function with the same
+    name, analogously to CONTINUE.
   * optimization: the compiler is smarter about representation selection for
     floating point constants used in full calls.
   * bug fix: deadlock detection could report the same deadlock twice, for
index 2015a77..05ac6e2 100644 (file)
@@ -1705,11 +1705,14 @@ the usual naming convention (names like *FOO*) for special variables"
   (define-nil-returning-restart continue ()
     "Transfer control to a restart named CONTINUE, or return NIL if none exists.")
   (define-nil-returning-restart store-value (value)
-    "Transfer control and VALUE to a restart named STORE-VALUE, or return NIL if
-   none exists.")
+    "Transfer control and VALUE to a restart named STORE-VALUE, or
+return NIL if none exists.")
   (define-nil-returning-restart use-value (value)
-    "Transfer control and VALUE to a restart named USE-VALUE, or return NIL if
-   none exists."))
+    "Transfer control and VALUE to a restart named USE-VALUE, or
+return NIL if none exists.")
+  (define-nil-returning-restart print-unreadably ()
+    "Transfer control to a restart named SB-EXT:PRINT-UNREADABLY, or
+return NIL if none exists."))
 
 ;;; single-stepping restarts
 
index 54c8c9b..33f12aa 100644 (file)
 (with-test (:name :bug-867684)
   (assert (equal "ab" (format nil "a~0&b"))))
 
+(with-test (:name :print-unreadably-function)
+  (assert (equal "\"foo\""
+                 (handler-bind ((print-not-readable #'sb-ext:print-unreadably))
+                   (write-to-string (coerce "foo" 'base-string) :readably t)))))
+
 ;;; success