Fwd: how to solve <<error printing object>>
Jacek Podkanski via Sbcl-help <[email protected]> Fri, 3 Apr 2026 17:33:53 +0100
| Newsgroups | gmane.lisp.steel-bank.general |
|---|---|
| Message-ID | <CAE9ibtqhEXQ+tG96JsbVT2DuYNaj093oS6HxerBqJkEmQ=m3Jg@mail.gmail.com> |
--===============6436267774980023617== Content-Type: multipart/alternative; boundary="000000000000b20d27064e90e24b" --000000000000b20d27064e90e24b Content-Type: text/plain; charset="UTF-8" I found the solution ---------- Forwarded message --------- From: Jacek Podkanski <[email protected]> Date: Fri, 3 Apr 2026 at 16:35 Subject: Re: [Sbcl-help] how to solve <<error printing object>> To: Dave Tenny <[email protected]> After all it was not a problem with circular objects, but with optional objects. Do I need a macro for such situations? (defmethod print-object ((obj male) stream) (print-unreadable-object (obj stream :type t :identity t) (format stream "~a" (list :name (~> obj name) :mother (let ((mother (mother obj))) (when mother (name mother))) :father (let ((father (father obj))) (when father (name father))) :children (loop for c in (~> obj children) collect (~> c name)) :wives (loop for w in (~> obj wives) collect (~> w name)) )))) I needed both special variables to understand the problem. (setf *break-on-signals* T) (setf *print-circle* T) On Thu, 2 Apr 2026 at 04:20, Jacek Podkanski <[email protected]> wrote: > Its 92 lines of code. > > running it in REPL > (load "~/Programming/Lisp/lispy-experiments/clos-family.lisp") > (in-package :clos-family) > (experiment) > --------------------- code ---------------------------------- > > (declaim (optimize (speed 1) (safety 3) (debug 3))) > > (eval-when (:compile-toplevel :load-toplevel :execute) > (ql:quickload '(:alexandria :serapeum :defclass-std))) > > (defpackage :clos-family > (:import-from :serapeum :~>) > (:import-from :defclass-std :defclass/std) > (:use #:cl)) > > ;; (load "~/Programming/Lisp/lispy-experiments/clos-family.lisp") > (in-package :clos-family) > > (defparameter *next-id* 0) > (defparameter *arbs* (make-hash-table)) > > ;;; > ============================================================================ > ;;; === classes > ================================================================ > (defclass/std arb () > ((id))) > > (defclass/std person (arb) > ((name :type string) > (mother) > (father) > (children))) > > (defclass/std male (person) > ((wives))) > > (defclass/std female (person) > ((husband))) > > ;;; === methods ========================= > > ;; these print object methods cause problems ------------------------- > > (defmethod print-object ((obj male) stream) > (print-unreadable-object (obj stream :type t :identity t) > (format stream "~a" > (list :name (~> obj name) > :mother :todo ;; (~> obj mother name) > :father :todo ;; (~> obj father name) > :children :todo ;;(loop for c in (~> obj children) > collect (~> c name)) > :wives :todo (loop for w in (~> obj wives) collect > (~> w name)) > )))) > > (defmethod print-object ((obj female) stream) > (print-unreadable-object (obj stream :type t :identity t) > (format stream "~a" > (list :name (~> obj name) > :mother :todo ;; (~> obj mother name) > :father :todo ;; (~> obj father name) > :children :todo ;; (loop for c in (~> obj children) > collect (~> c name)) > :husband :todo > ;; (name (husband obj)) > )))) > > (defmethod initialize-instance :after ((obj arb) &key) > (let ((new-id (incf *next-id*))) > (setf (~> obj id) new-id) > (setf (gethash new-id *arbs*) obj))) > > (defmethod marry ((groom male) (bride female)) > (let ((husband groom) > (wife bride)) > (setf (~> wife husband) husband) > (setf (~> husband wives) (cons wife (~> husband wives))))) > > (defmethod give-birth-male ((father male) (mother female) name) > (let ((child (make-instance 'male :name name :mother mother :father > father))) > (pushnew child (~> father children)) > (pushnew child (~> mother children)))) > > (defmethod give-birth-female ((father male) (mother female) name) > (let ((child (make-instance 'female :name name :mother mother :father > father))) > (pushnew child (~> father children)) > (pushnew child (~> mother children)))) > > ;; (experiment) > (defun experiment () > (let ((aaa *arbs*)) > (setf *break-on-signals* T) > (let ((abraham (make-instance 'male :name "Abraham")) > (sarah (make-instance 'female :name "Sarah")) > (hagar (make-instance 'female :name "Hagar"))) > (marry abraham sarah) > (marry abraham hagar) > (give-birth-male abraham hagar "Ishmael") > (give-birth-male abraham sarah "Isaac") > > (break "examine arbs ~S" aaa))) > ;; end > ) > > On Thu, 2 Apr 2026 at 04:09, Dave Tenny via Sbcl-help < > [email protected]> wrote: > >> Is there more to the error? For example, I had an error printing objects >> the other day because I it was from a thread in which bt2:make-thread >> defaults *print-readably* to T, and my print-object methods were printing >> unreadable objects. >> On 4/1/26 8:13 PM, Jacek Podkanski via Sbcl-help wrote: >> >> setting *print-circle* to T did not work >> >> On Thu, 2 Apr 2026 at 00:44, Jacek Podkanski <[email protected]> >> wrote: >> >>> I was able to make progress with replacing slot values with todos, but >>> still do not know how to fix such problems >>> >>> (defmethod print-object ((obj male) stream) >>> (print-unreadable-object (obj stream :type t :identity t) >>> (format stream "bbbb ~a" >>> (list :name :todo ;; (~> obj name) >>> :mother :todo ;; (~> obj mother name) >>> :father :todo ;; (~> obj father name) >>> :children :todo ;; (loop for c in (~> obj children) >>> collect (~> c name)) >>> :wives :todo ;; (loop for w in (~> obj wives) >>> collect (~> w name)) >>> )))) >>> >>> On Thu, 2 Apr 2026 at 00:40, Jacek Podkanski <[email protected]> >>> wrote: >>> >>>> I am looking for guidelines on solving <<error printing object>> >>>> error. >>>> >>>> I am trying to learn CLOS parts related to relationships between >>>> objects. >>>> >>>> I tried to model ancient family relations where some lived in >>>> monogamous and some polygamous relationships. And it's not simple. >>>> >>>> I suspect there is going in circles involved, but I have no idea how to >>>> solve it. >>>> >>>> I can provide full source if needed. >>>> >>>> ;;; === classes ================= >>>> (defclass/std arb () >>>> ((id))) >>>> >>>> (defclass/std person (arb) >>>> ((name :type string) >>>> (mother) >>>> (father) >>>> (children))) >>>> >>>> (defclass/std male (person) >>>> ((wives))) >>>> >>> _______________________________________________ >> Sbcl-help mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/sbcl-help >> > --000000000000b20d27064e90e24b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">I found the solution<div><br><div class=3D"gmail_quote gma= il_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">---------- Forwar= ded message ---------<br>From: <b class=3D"gmail_sendername" dir=3D"auto">J= acek Podkanski</b> <span dir=3D"auto"><<a href=3D"mailto:ruby.object@goo= glemail.com">[email protected]</a>></span><br>Date: Fri, 3 Apr = 2026 at 16:35<br>Subject: Re: [Sbcl-help] how to solve <<error printi= ng object>><br>To: Dave Tenny <<a href=3D"mailto:dave.tenny@proton= mail.com">[email protected]</a>><br></div><br><br><div dir=3D"lt= r"><div>After all it was not a problem with circular objects, but with opti= onal objects.</div><div>Do I need a macro for such situations?</div><div><b= r></div><div>(defmethod print-object ((obj male) stream)<br>=C2=A0 (print-u= nreadable-object (obj stream :type t :identity t)<br>=C2=A0 =C2=A0 (format = stream "~a"<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (list :n= ame =C2=A0 =C2=A0(~> obj name)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 :mother =C2=A0(let ((mother (mother obj))) (when m= other (name mother)))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 :father=C2=A0 =C2=A0 (let ((father (father obj))) (when fathe= r (name father)))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 :children (loop for c in (~> obj children) collect (~> c n= ame))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :wi= ves =C2=A0 =C2=A0(loop for w in (~> obj wives) collect (~> w name))<b= r>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ))))<br><b= r></div><div>I needed both special variables to understand the problem.=C2= =A0</div><div>=C2=A0 =C2=A0 (setf *break-on-signals* T)<br>=C2=A0 =C2=A0 (s= etf *print-circle* T)<br><br></div></div><br><div class=3D"gmail_quote"><di= v dir=3D"ltr" class=3D"gmail_attr">On Thu, 2 Apr 2026 at 04:20, Jacek Podka= nski <<a href=3D"mailto:[email protected]" target=3D"_blank">ru= [email protected]</a>> wrote:<br></div><blockquote class=3D"gmail= _quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204= ,204);padding-left:1ex"><div dir=3D"ltr">Its 92 lines of code.=C2=A0<div><b= r></div><div>running it in REPL<br><div>(load =C2=A0"~/Programming/Lis= p/lispy-experiments/clos-family.lisp")</div><div>(in-package :clos-fam= ily)</div><div>(experiment)</div><div>--------------------- code ----------= ------------------------<br><div><br></div><div>(declaim (optimize (speed 1= ) (safety 3) (debug 3)))<br><br>(eval-when (:compile-toplevel :load-topleve= l :execute)<br>=C2=A0 (ql:quickload '(:alexandria :serapeum :defclass-s= td)))<br><br>(defpackage :clos-family<br>=C2=A0 (:import-from :serapeum :~&= gt;)<br>=C2=A0 (:import-from :defclass-std :defclass/std)<br>=C2=A0 (:use #= :cl))<br><br>;; (load =C2=A0"~/Programming/Lisp/lispy-experiments/clos= -family.lisp")<br>(in-package :clos-family)<br><br>(defparameter *next= -id* 0)<br>(defparameter *arbs* (make-hash-table))<br><br>;;; =3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>;;; = =3D=3D=3D classes =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>(defclass/s= td arb ()<br>=C2=A0 ((id)))<br><br>(defclass/std person (arb)<br>=C2=A0 ((n= ame :type string)<br>=C2=A0 =C2=A0(mother)<br>=C2=A0 =C2=A0(father)<br>=C2= =A0 =C2=A0(children)))<br><br>(defclass/std male =C2=A0 (person)<br>=C2=A0 = ((wives)))<br><br>(defclass/std female (person)<br>=C2=A0 ((husband)))<br><= br>;;; =3D=3D=3D methods =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D<br><br>;; these print object methods cause prob= lems -------------------------</div><div><br>(defmethod print-object ((obj = male) stream)<br>=C2=A0 (print-unreadable-object (obj stream :type t :ident= ity t)<br>=C2=A0 =C2=A0 (format stream "~a"<br>=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (list :name =C2=A0 =C2=A0(~> obj name)<br>=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :mother :todo ;= ; (~> obj mother name)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 :father =C2=A0 :todo ;; (~> obj father name)<br>=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :children :todo ;;= (loop for c in (~> obj children) collect (~> c name))<br>=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :wives =C2=A0:todo =C2= =A0 (loop for w in (~> obj wives) collect (~> w name))<br>=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ))))<br><br>(defmethod= print-object ((obj female) stream)<br>=C2=A0 (print-unreadable-object (obj= stream :type t :identity t)<br>=C2=A0 =C2=A0 (format stream "~a"= <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (list :name =C2=A0 =C2=A0(~&g= t; obj name)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 :mother =C2=A0:todo ;; (~> obj mother name)<br>=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :father =C2=A0:todo ;; (~> obj= father name)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 :children :todo ;; (loop for c in (~> obj children) collect (~>= ; c name))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 :husband :todo<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 ;; (name (husband obj))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 ))))<br><br>(defmethod initialize-instance :aft= er ((obj arb) &key)<br>=C2=A0 (let ((new-id (incf *next-id*)))<br>=C2= =A0 =C2=A0 (setf (~> obj id) new-id)<br>=C2=A0 =C2=A0 (setf (gethash new= -id *arbs*) obj)))<br><br>(defmethod marry ((groom male) (bride female))<br= >=C2=A0 (let ((husband groom)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (wife =C2=A0 = =C2=A0bride))<br>=C2=A0 =C2=A0 (setf (~> wife husband) husband)<br>=C2= =A0 =C2=A0 (setf (~> husband wives) (cons wife (~> husband wives)))))= <br><br>(defmethod give-birth-male =C2=A0 ((father male) (mother female) na= me)<br>=C2=A0 (let ((child (make-instance 'male :name name :mother moth= er :father father)))<br>=C2=A0 =C2=A0 (pushnew child (~> father children= ))<br>=C2=A0 =C2=A0 (pushnew child (~> mother children))))<br><br>(defme= thod give-birth-female ((father male) (mother female) name)<br>=C2=A0 (let = ((child (make-instance 'female :name name :mother mother :father father= )))<br>=C2=A0 =C2=A0 (pushnew child (~> father children))<br>=C2=A0 =C2= =A0 (pushnew child (~> mother children))))<br><br>;; (experiment)<br>(de= fun experiment ()<br>=C2=A0 (let ((aaa *arbs*))<br>=C2=A0 =C2=A0 (setf *bre= ak-on-signals* T)<br>=C2=A0 =C2=A0 (let ((abraham (make-instance 'male = :name "Abraham"))<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (sarah (m= ake-instance 'female :name "Sarah"))<br>=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (hagar (make-instance 'female :name "Hagar")))<= br>=C2=A0 =C2=A0 =C2=A0 (marry abraham sarah)<br>=C2=A0 =C2=A0 =C2=A0 (marr= y abraham hagar)<br>=C2=A0 =C2=A0 =C2=A0 (give-birth-male abraham hagar &qu= ot;Ishmael")<br>=C2=A0 =C2=A0 =C2=A0 (give-birth-male abraham sarah &q= uot;Isaac")<br><br>=C2=A0 =C2=A0 =C2=A0 (break "examine arbs ~S&q= uot; aaa)))<br>=C2=A0 ;; end<br>=C2=A0 )<br></div></div></div></div><br><di= v class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, 2 Apr= 2026 at 04:09, Dave Tenny via Sbcl-help <<a href=3D"mailto:sbcl-help@li= sts.sourceforge.net" target=3D"_blank">[email protected]</a>&= gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0= px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></= u> =20 =20 =20 <div> <p>Is there more to the error?=C2=A0 For example, I had an error printi= ng objects the other day because I it was from a thread in which bt2:make-thread defaults *print-readably* to T, and my print-object methods were printing unreadable objects.</p> <div>On 4/1/26 8:13 PM, Jacek Podkanski via Sbcl-help wrote:<br> </div> <blockquote type=3D"cite"> <div dir=3D"ltr">setting *print-circle* to T did not work</div> <br> <div class=3D"gmail_quote"> <div dir=3D"ltr" class=3D"gmail_attr">On Thu, 2 Apr 2026 at 00:44, Jacek Podkanski <<a href=3D"mailto:[email protected]"= target=3D"_blank">[email protected]</a>> wrote:<br> </div> <blockquote class=3D"gmail_quote"> <div dir=3D"ltr">I was able to make progress with replacing slot values with todos, but still do not know how to fix such problems <div><br> </div> <div>(defmethod print-object ((obj male) stream)<br> =C2=A0 (print-unreadable-object (obj stream :type t :identity t)<br> =C2=A0 =C2=A0 (format stream "bbbb ~a"<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (list :name =C2=A0 = =C2=A0:todo ;; (~> obj name)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 :mother =C2=A0:todo ;; (~> obj mother name)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 :father =C2=A0:todo ;; (~> obj father name)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 :children :todo ;; (loop for c in (~> obj children) collect (~> c name))<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 :wives =C2=A0:todo =C2=A0;; (loop for w in (~> obj wives) collect (~> w name))<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 ))))<br> </div> </div> <br> <div class=3D"gmail_quote"> <div dir=3D"ltr" class=3D"gmail_attr">On Thu, 2 Apr 2026 at 00:40, Jacek Podkanski <<a href=3D"mailto:ruby.object@goog= lemail.com" target=3D"_blank">[email protected]</a>> wrote:<br> </div> <blockquote class=3D"gmail_quote"> <div dir=3D"ltr">I am looking for guidelines on solving=C2=A0=C2=A0<<error printing object>> er= ror. <div><br> </div> <div>I am trying to learn CLOS parts related to relationships between objects.</div> <div><br> </div> <div>I tried to model ancient family relations where some lived in monogamous and some polygamous relationships. And it's not simple.=C2=A0</div> <div><br> </div> <div>I suspect there is going in circles involved, but I have no idea how to solve it.</div> <div><br> </div> <div>I can provide full source if needed.</div> <div><br> </div> <div>;;; =3D=3D=3D classes =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D<br> (defclass/std arb ()<br> =C2=A0 ((id)))<br> <br> (defclass/std person (arb)<br> =C2=A0 ((name :type string)<br> =C2=A0 =C2=A0(mother)<br> =C2=A0 =C2=A0(father)<br> =C2=A0 =C2=A0(children)))<br> <br> (defclass/std male =C2=A0 (person)<br> =C2=A0 ((wives)))<br> </div> </div> </blockquote> </div> </blockquote> </div> </blockquote> </div> _______________________________________________<br> Sbcl-help mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Sbcl-h= [email protected]</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/sbcl-help" rel=3D"n= oreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/s= bcl-help</a><br> </blockquote></div> </blockquote></div> </div></div></div> --000000000000b20d27064e90e24b-- --===============6436267774980023617== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============6436267774980023617== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Sbcl-help mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sbcl-help --===============6436267774980023617==--