The less-familiar parts of Lisp for beginners — print-unreadable-object

Having discussed pretty-printing and print-object, now we come to a macro, print-unreadable-object, that is used to simplify the printing of objects that are deemed unreadable.  You’ve probably seen such output in the past, when printing instances of CLOS classes.  Where arrays and lists might print their contents, the Lisp printer just produces a brief output to indicate the class from which this instance was built, and an implentation-defined representation of the instance’s identity (often a memory address).

The programmer is likely to use this macro in a custom print-object method, to augment the normal printed representation of the class rather than printing the full contents.  The HyperSpec contains a good example of the use in that case.  Note that it can be used in other contexts, as follows:
*slime-repl sbcl*

CL-USER> (let ((mylist '(1 2 3)))
           (print-unreadable-object
               (mylist *standard-output* :type t :identity t)
             (format t "{{Uninteresting contents}}")))
#<CONS {{Uninteresting contents}} {1004DDE997}>
NIL

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.