From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Daniel Llorens Newsgroups: gmane.lisp.guile.bugs Subject: bug#29684: exception printers - request for improvement Date: Thu, 14 Dec 2017 15:38:18 +0100 Message-ID: <75FC7864-12FB-4C11-A154-409A596FEB17@bluewin.ch> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_FA577E85-4A48-4D93-B0A0-81A700BF3CF0" X-Trace: blaine.gmane.org 1513262418 29093 195.159.176.226 (14 Dec 2017 14:40:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 14 Dec 2017 14:40:18 +0000 (UTC) To: 29684@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Thu Dec 14 15:40:14 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePUgH-00073e-0r for guile-bugs@m.gmane.org; Thu, 14 Dec 2017 15:40:13 +0100 Original-Received: from localhost ([::1]:41300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePUgJ-0005Jm-KR for guile-bugs@m.gmane.org; Thu, 14 Dec 2017 09:40:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePUfC-0004i9-UT for bug-guile@gnu.org; Thu, 14 Dec 2017 09:39:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePUf8-0002hG-Sv for bug-guile@gnu.org; Thu, 14 Dec 2017 09:39:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52701) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ePUf8-0002gt-Nt for bug-guile@gnu.org; Thu, 14 Dec 2017 09:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ePUf8-0005Sw-8m for bug-guile@gnu.org; Thu, 14 Dec 2017 09:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Llorens Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 14 Dec 2017 14:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29684 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 29684-submit@debbugs.gnu.org id=B29684.151326231320967 (code B ref 29684); Thu, 14 Dec 2017 14:39:02 +0000 Original-Received: (at 29684) by debbugs.gnu.org; 14 Dec 2017 14:38:33 +0000 Original-Received: from localhost ([127.0.0.1]:33149 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePUed-0005S5-7C for submit@debbugs.gnu.org; Thu, 14 Dec 2017 09:38:31 -0500 Original-Received: from vimdzmsp-sfwd04.bluewin.ch ([195.186.227.132]:33316 helo=smtpauths.lb.bluewin.ch) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePUeY-0005Rk-H9 for 29684@debbugs.gnu.org; Thu, 14 Dec 2017 09:38:27 -0500 Original-Received: from [10.42.0.160] ([213.193.80.99]) by vimdzmsp-sfwd04.bluewin.ch Swisscom AG with SMTP id PUeReUq5lEMC4PUeSehNMx; Thu, 14 Dec 2017 15:38:20 +0100 X-Bluewin-Spam-Analysis: v=2.1 cv=R6vOYYlX c=1 sm=1 tr=0 a=DzaHVtLsrNCQ5PccsnG91A==:117 a=DzaHVtLsrNCQ5PccsnG91A==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=mDV3o1hIAAAA:8 a=r3sLHcF3gtLLsd-G3P8A:9 a=pILNOxqGKmIA:10 a=GAgZYncLulQA:10 a=FWqoJnpfysoA:10 a=xX9s1JTShJ8A:10 a=oo02T4f9SFw6BvWe:21 a=_W_S_7VecoQA:10 a=_FVE-zBwftR9WsbkzFJk:22 X-Bluewin-Spam-Score: 0.00 X-FXIT-IP: IPv4[213.193.80.99] Epoch[1513262300] X-Bluewin-AuthAs: dll@bluewin.ch In-Reply-To: X-Mailer: Apple Mail (2.1878.6) X-CMAE-Envelope: MS4wfEYXdTYa5mzsyAFG5n8G+fKNpL/FynyA/duCvlTATMhx1/kqNkZb0ovLFbSXcyEIMJKjh+eyIAbx6sWxlpnBCwgbnqMhA4F4FH2y1lhO7/7dWyLq7mVd Se3/HUv2Ag79t8V+Uy8dtZtvYLqIaLCutnKM3js3V2tup51fGKQ5SCxIjLk/mCPKQD2y4y2oLqdT+OqoascKvFXKIOFRhrgPnM0= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8931 Archived-At: --Apple-Mail=_FA577E85-4A48-4D93-B0A0-81A700BF3CF0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Agreed with David that this is an important issue. Without a patch, = working with a large data structure is guaranteed to kill the REPL = session sooner or later. There was a thread a while ago here: = https://lists.gnu.org/archive/html/guile-user/2017-02/msg00188.html Right now, the REPL will catch either general exceptions or calls to = error or scm-error which throw specific exception types. For general = exceptions the argument list is just printed with ~a, but for libguile = exceptions, the handler expects a =91format=92 argument which is used to = format the error message. One can put ~a and ~s in this =91format=92 = argument, see = https://www.gnu.org/software/guile/manual/html_node/Handling-Errors.html. The proposal > (use-modules (ice-9 pretty-print)) >=20 > (when (defined? 'exception-format) > (set! exception-format > (lambda (port fmt . args) > (for-each (lambda (arg) > (truncated-print arg #:port port)) > args)))) throws away this formatting. That's why I proposed instead the other = solution in the links above, which replaces the ~a and ~s by ~y (this = calls truncated print), but otherwise respects the original format = string. (set! exception-format (lambda (port fmt . args) (apply format port (rewrite-fmt (rewrite-fmt fmt "~s") "~a") = args))) Anyway. These are clunky hacks. According to the manual > ~A indicates an argument printed using display, while ~S indicates an = argument printed using write I think this is an unnecessary complication if there's a hook. One = option (that works like =91write=92 by default) is enough. If one wants = to craft a special error message, that should be done without abusing = the exception arguments. I think this =91write=92 should be a hook or even a fluid. There is = already a hook to configure the REPL printer, which is set by = (repl-default-option-set! 'print ##) or (repl-option-set! repl 'print = ##) (the latter is undocumented). Maybe that hook can be reused for the = exception printer. Or maybe there can be a new hook that is reused by = both the repl and the exception printer. It makes sense to me to make = both of these refer to the same function. I also agree with David that both the REPL and the exception printers = should be truncated by default. That requires truncated-print to be = available in (ice-9 boot). Anyway, just some thoughts. See the related bug#29669 about REPL printers.=20 Regards Daniel= --Apple-Mail=_FA577E85-4A48-4D93-B0A0-81A700BF3CF0 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252

Agreed with David that this is = an important issue. Without a patch, working with a large data structure = is guaranteed to kill the REPL session sooner or later. There was a thread a while = ago here: https://lists.gnu.org/archive/html/guile-user/2017-02/msg00188.html=

Right now, the REPL will catch either general = exceptions or calls to error or scm-error which throw specific exception = types. For general exceptions the argument list is just printed with ~a, = but for libguile exceptions, the handler expects a =91format=92 argument = which is used to format the error message. One can put ~a and ~s in this = =91format=92 argument, see https://www.gnu.org/software/guile/manual/html_node/Handling-Error= s.html.

The = proposal

= (use-modules (ice-9 pretty-print))

(when = (defined? 'exception-format)
 (set! = exception-format
=        (lambda (port fmt . = args)
=          (for-each = (lambda (arg)
= =             &n= bsp;        (truncated-print arg = #:port port))
= =             &n= bsp;args))))

throws away this = formatting. That's why I proposed instead the other solution in the = links above, which replaces the ~a and ~s by ~y (this calls truncated = print), but otherwise respects the original format = string.

(set! = exception-format
         (lambda = (port fmt . args)
          =  (apply format port (rewrite-fmt (rewrite-fmt fmt "~s") "~a") = args)))

Anyway. These are clunky hacks. = According to the = manual

~A indicates an argument printed using display, while ~S = indicates an argument printed using = write

I think = this is an unnecessary complication if there's a hook. One option (that = works like =91write=92 by default) is enough. If one wants to craft a = special error message, that should be done without abusing the exception = arguments.

I think this =91write=92 = should be a hook or even a fluid. There is already a hook to configure = the REPL printer, which is set by (repl-default-option-set! 'print ##) = or (repl-option-set! repl 'print ##) (the latter is undocumented). Maybe = that hook can be reused for the exception printer. Or maybe there can be = a new hook that is reused by both the repl and the exception printer. It = makes sense to me to make both of these refer to the same = function.

I also agree with David that both the = REPL and the exception printers should be truncated by default. That = requires truncated-print to be available in (ice-9 = boot).

Anyway, just some = thoughts.

See the related bug#29669 about REPL = printers. 

Regards

Daniel
= --Apple-Mail=_FA577E85-4A48-4D93-B0A0-81A700BF3CF0--