emacs-devel
[Top][All Lists]
Advanced

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

Re: `unreadablep'


From: Lars Ingebrigtsen
Subject: Re: `unreadablep'
Date: Wed, 15 Dec 2021 09:35:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Po Lu <luangruo@yahoo.com> writes:

> Yes, it would be very convenient indeed.
>
> I think the best solution would be to allow `prin1' to optionally return
> whether or not any unreadable objects were printed, instead of the
> object itself.

I was thinking that for efficiency (and ease of usage), nothing would be
printed.  That is, something like

(defun unreadablep (object)
  (condition-case nil
      (prin1 object 'error-on-unprintable)
    (:success t)
    (unprintable-error nil)))

and then prin1 would signal an error if it encounters an unprintable
object in the structure, but otherwise print nothing.

But I still haven't actually looked at the prin1 code, so I'm not sure
whether that would be messy or not.  😀 The advantage of using the prin1
code to do the checking (instead of implementing a separate function to
traverse the data itself) is that we'd be pretty sure that there aren't
any glitches between the prin1 implementation and the checker
implementation...

But having `prin1' return whether it printed something unreadable also
sounds attractive.  I guess it depends on the use case.  If you're
saying

(if (unprintable o)
    (insert ";; " (prin1 o (current-buffer)))
  (prin1 o (current-buffer)))

then you're traversing the data twice, which isn't efficient, so
inserting it first and then checking would be nice.  But if you're doing

(when (unprintable o)
  (error "Nope"))

then it'd be inconvenient for it to be printing anything.

And what about `prin1-to-string'?  It has to return the string...  Hm...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



reply via email to

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