PRINT-CIRCLE-STRUCTURET. This prevents printing circular structures that point to objects that cannot be printed and prevents the development of new printed representations that can be read by the reader.
Proposal PRINT-CIRCLE-STRUCTURE:USER-FUNCTIONS-WORK:
When *print-circle* is T, a user defined print-function can print objects to the supplied stream using WRITE, PRIN1, PRINC, or FORMAT and expect circularities to be detected and printed using #n# syntax. If a user defined print-function prints to a stream other than the one that was supplied, then circularity detection starts over for that stream. This applies to methods on PRINT-OBJECT in addition to :PRINT-FUNCTION options.
;;; ;;; Define a structure that can be circular and that has a slot with a ;;; value that cannot be printed. ;;; (defstruct (TEST (:print-function print-test)) ptr (function #'(lambda (x) (error "No function is defined."))))
;;; ;;; This print function generates a machine readable printed ;;; representation for a structure with a slot that cannot be printed. ;;; (defun PRINT-TEST (structure stream depth) (format stream "#S(TEST PTR ~S)" (test-ptr structure)))
;;;
;;; Define two structures that point to each other. If this
;;; expression successfully evaluates at the top level, then the
;;; printed result should look like:
;;; #1=#S(TEST PTR #S(TEST PTR #1#))
;;;
;;; If it does not work then it will generate an infinite printed
;;; representation.
(setf *print-circle* t
*a (make-test)
*b (make-test)
(test-ptr *a) *b
(test-ptr *b) *a)
LISP provides two mechanisms for these problems (*print-circle* and the :print-function option to defstruct), but they do not currently work together in most implementations.KCL, Coral and Franz do not work.Cost to Users: None
LISP structures is of minimal usefulness. In almost any real application, there are circular structures with non printable objects such as closures and hash tables that need to be printed. In addition the development of printers for new reader macros becomes much more of an effort then it should be since it requires reimplementing the complete circularity detection mechanism.LISP data structures.