* bug#30070: 27.0.50; cl-print sometimes prints self-referencing objects as #1=#<thing>
@ 2018-01-10 19:39 Michael Heerdegen
2018-01-10 20:39 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Michael Heerdegen @ 2018-01-10 19:39 UTC (permalink / raw)
To: 30070; +Cc: Stefan Monnier
Hi,
my use case is like this:
--8<---------------cut here---------------start------------->8---
;; -*- lexical-binding: t -*-
(require 'cl-lib)
(require 'cl-print)
(cl-defstruct thing
thing-object)
(cl-defmethod cl-print-object ((_object thing) stream)
(princ "#<thing>" stream))
(let ((print-circle t))
(cl-prin1-to-string
(letrec ((me (make-thing :thing-object (lambda () me))))
me)))
--8<---------------cut here---------------end--------------->8---
That gives me "#1=#<thing>". That's weird because the printed
representation of the thing doesn't refer to itself. This can happen in
real life: that the thing-object in the example is a closure referencing
the thing itself might be coincidence, so one can't assume that the
printed representation of a self-referential object always includes a
reference to the top-level object.
TIA,
Michael.
In GNU Emacs 27.0.50 (build 11, x86_64-pc-linux-gnu, GTK+ Version 3.22.26)
of 2018-01-10 built on drachen
Repository revision: bf38966965384b07621839db892b90932b8754a6
Windowing system distributor 'The X.Org Foundation', version 11.0.11905000
System Description: Debian GNU/Linux testing (buster)
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#30070: 27.0.50; cl-print sometimes prints self-referencing objects as #1=#<thing>
2018-01-10 19:39 bug#30070: 27.0.50; cl-print sometimes prints self-referencing objects as #1=#<thing> Michael Heerdegen
@ 2018-01-10 20:39 ` Stefan Monnier
2018-01-11 14:45 ` Michael Heerdegen
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2018-01-10 20:39 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: 30070
> That gives me "#1=#<thing>". That's weird because the printed
> representation of the thing doesn't refer to itself.
Yes, it's a known misfeature (to me at least). I don't know how we
could fix it, tho: the cycle-detection is done in a preprocessing phase
which doesn't know about any print format (nor about cl-print), so by
the time we learn the the object will be printed as "#<thing>", we have
already printed "#1=".
To fix it, I have the impression that we'd have to make cl-print a lot
more complex, and potentially its API as well (e.g. add a matching
cl-preprocess method additionally to cl-print-object).
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#30070: 27.0.50; cl-print sometimes prints self-referencing objects as #1=#<thing>
2018-01-10 20:39 ` Stefan Monnier
@ 2018-01-11 14:45 ` Michael Heerdegen
2018-01-11 15:10 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Michael Heerdegen @ 2018-01-11 14:45 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 30070
Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
> > That gives me "#1=#<thing>". That's weird because the printed
> > representation of the thing doesn't refer to itself.
>
> Yes, it's a known misfeature (to me at least). I don't know how we
> could fix it, tho: the cycle-detection is done in a preprocessing phase
> which doesn't know about any print format (nor about cl-print), so by
> the time we learn the the object will be printed as "#<thing>", we have
> already printed "#1=".
>
> To fix it, I have the impression that we'd have to make cl-print a lot
> more complex, and potentially its API as well (e.g. add a matching
> cl-preprocess method additionally to cl-print-object).
Yes, that's what I expected.
Would it make sense to cache what is being printed, post-process it, and
print it at once?
Michael.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#30070: 27.0.50; cl-print sometimes prints self-referencing objects as #1=#<thing>
2018-01-11 14:45 ` Michael Heerdegen
@ 2018-01-11 15:10 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2018-01-11 15:10 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: 30070
> Would it make sense to cache what is being printed, post-process it, and
> print it at once?
We could try, but we'd have to somehow distinguish the "#N=" and "#N#"
that are used for such sharing references from those that may appear as
part of "normal user output".
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-01-11 15:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-10 19:39 bug#30070: 27.0.50; cl-print sometimes prints self-referencing objects as #1=#<thing> Michael Heerdegen
2018-01-10 20:39 ` Stefan Monnier
2018-01-11 14:45 ` Michael Heerdegen
2018-01-11 15:10 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.