From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Qiantan Hong Newsgroups: gmane.emacs.devel Subject: Re: `unreadablep' Date: Wed, 15 Dec 2021 16:04:08 +0000 Message-ID: <68242383-4C03-48A8-857F-CEA53F372590@mit.edu> References: <87bl1imhnd.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14162"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "emacs-devel@gnu.org" To: "sds@gnu.org" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 15 17:24:04 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxX4V-0003TF-EP for ged-emacs-devel@m.gmane-mx.org; Wed, 15 Dec 2021 17:24:03 +0100 Original-Received: from localhost ([::1]:57658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxX4U-0001sW-5C for ged-emacs-devel@m.gmane-mx.org; Wed, 15 Dec 2021 11:24:02 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxWm0-0003W3-Me for emacs-devel@gnu.org; Wed, 15 Dec 2021 11:04:58 -0500 Original-Received: from outgoing-exchange-5.mit.edu ([18.9.28.59]:52329) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxWlq-0001NY-Id for emacs-devel@gnu.org; Wed, 15 Dec 2021 11:04:53 -0500 Original-Received: from oc11exedge1.exchange.mit.edu (OC11EXEDGE1.EXCHANGE.MIT.EDU [18.9.3.17]) by outgoing-exchange-5.mit.edu (8.14.7/8.12.4) with ESMTP id 1BFG4Mm9004336; Wed, 15 Dec 2021 11:04:38 -0500 Original-Received: from w92expo16.exchange.mit.edu (18.7.74.70) by oc11exedge1.exchange.mit.edu (18.9.3.17) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Wed, 15 Dec 2021 11:03:11 -0500 Original-Received: from oc11expo16.exchange.mit.edu (18.9.4.47) by w92expo16.exchange.mit.edu (18.7.74.70) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 15 Dec 2021 11:04:08 -0500 Original-Received: from oc11expo16.exchange.mit.edu ([18.9.4.47]) by oc11expo16.exchange.mit.edu ([18.9.4.47]) with mapi id 15.00.1497.023; Wed, 15 Dec 2021 11:04:08 -0500 Thread-Topic: `unreadablep' Thread-Index: AQHX8Yw/j9AhzcoD/0uXIC6gYsX+RKw0C4EA In-Reply-To: Accept-Language: en-US Content-Language: en-US x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [128.12.11.144] Content-ID: <305C62CC2E4BB7488FA66928E3B956B7@exchange.mit.edu> Received-SPF: pass client-ip=18.9.28.59; envelope-from=qhong@mit.edu; helo=outgoing-exchange-5.mit.edu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:282066 Archived-At: > On Dec 15, 2021, at 7:32 AM, Steingold wrote: >=20 >> * Lars Ingebrigtsen [2021-12-15 08:49:58 +0100]: >>=20 >> Do we have any primitive that can be used to check whether an object is >> printable or not? Code like this (from savehist.el) makes me believe >> "not": >>=20 >> ;; Print elements of VALUE one by one, carefully. >> (dolist (elt value) >> (let ((start (point))) >> (insert " ") >> ;; Try to print and then to read an element. >> (condition-case nil >> (progn >> (prin1 elt (current-buffer)) >> (save-excursion >> (goto-char start) >> (read (current-buffer)))) >> (error >> ;; If writing or reading gave an error, comment it out. >> (goto-char start) >> (insert "\n") >> (while (not (eobp)) >> (insert ";;; ") >> (forward-line 1)) >> (insert "\n"))) >> (goto-char (point-max)))) >>=20 >> It would be nice to have such a function (i.e., that says whether it can >> be read back after printing it). 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? >>=20 >> Does anybody have any thoughts on this issue? >=20 > I think the above code is _perfect_. > Why would one want to know in advance if the object is printable readably= ? > Only to decide how to print it, right? > Then the optimal approach is to _try_ to print readably and then take an > alternative/remedial action on failure. > This will usually save a structure traversal. print already traverse it once, read traverse it twice. If print support it natively we save in the best case one half of the work.