emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `unreadablep'


From: Philipp Stephani
Subject: Re: `unreadablep'
Date: Wed, 15 Dec 2021 21:21:05 +0100

Am Mi., 15. Dez. 2021 um 09:16 Uhr schrieb Lars Ingebrigtsen <larsi@gnus.org>:
> It would be nice to have such a function (i.e., that says whether it can
> be read back after printing it).

Yes, this would be useful in many places where we need to serialize
Lisp objects (e.g. for the sandbox stuff).

>  The problem is, of course, complex
> structures that require recursing (and then checking for loops), etc, so
> you basically have to implement it the way printing is done if you want
> it to be fast, I think?

It's a DFS of a DAG, not quite rocket science. The difficulty is
rather in getting the details right (e.g. you can't allow symbols
interned in a non-default obarray because you wouldn't get the same
symbol back).

> I wonder whether this could be efficiently implemented by, say, having
> some kind of special value for PRINTCHARFUN for prin1, but I haven't
> looked at the code yet.

Maybe just introduce another C function `prin1-if-readable' or so that
errors out (with a specific error symbol so that callers can catch it)
if the object can't be printed in a readable way. That should also
bind the print variables correctly (e.g. bind print-level to nil) so
ensure that the result really represents an equivalent List object.
The new function would likely reuse the existing `print' machinery,
with the `escapeflag' parameter turned into a generic `flags' enum.
I guess it would make sense to also forbid some "exotic" objects
(circular objects, uninterned symbols) that rarely make sense to
serialize.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]