Skip to content

Instantly share code, notes, and snippets.

@cbaggers
Last active April 5, 2019 11:12
Show Gist options
  • Save cbaggers/5cea7e636090b6ad1a4a8ec19bfac6d4 to your computer and use it in GitHub Desktop.
Save cbaggers/5cea7e636090b6ad1a4a8ec19bfac6d4 to your computer and use it in GitHub Desktop.
Making circular list in print-object fails to print even when *print-circle* is T
(eval-when (:compile-toplevel :load-toplevel :execute)
(setf *print-circle* t))
#||
How to trigger issue:
First run (make-instance 'trigger-object) to see the overflow.
Then run (make-circular) to see that the list created in print-object
should have been printable.
||#
(defclass trigger-object () ())
(defun make-circular ()
(let ((thing (make-list 3)))
(setf (second thing) thing
(third thing) thing)
thing))
(defmethod print-object ((obj trigger-object) stream)
(format stream "#<CT2 ~a>" (make-circular)))
@cbaggers
Copy link
Author

cbaggers commented Apr 5, 2019

this works, suggesting issue with how circular refs were worked out in first pass

(eval-when (:compile-toplevel :load-toplevel :execute)
  (setf *print-circle* t))

(defclass trigger-object () ())

(defun make-circular ()
  (let ((thing (make-list 3)))
    (setf (second thing) thing
          (third thing) thing)
    thing))


(defvar *shit-cache* (make-hash-table))
(defmethod print-object ((obj trigger-object) stream)
  (let ((desig (or (gethash obj *shit-cache*)
                   (setf (gethash obj *shit-cache*)
                         (make-circular)))))
    (format stream "#<CT2 ~a>" desig)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment