From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.lisp.guile.bugs Subject: bug#71684: [PATCH v2] Add peek-error, pke. Date: Mon, 28 Oct 2024 11:33:49 +0100 Organization: AvatarAcademy.nl Message-ID: <871q00ikj6.fsf__15763.8778489613$1730111814$gmane$org@gnu.org> References: <20240619114411.7302-1-janneke@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28510"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 71684@debbugs.gnu.org To: guile-devel@gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Mon Oct 28 11:36:46 2024 Return-path: Envelope-to: guile-bugs@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 1t5N77-0007Fk-DN for guile-bugs@m.gmane-mx.org; Mon, 28 Oct 2024 11:36:45 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5N6q-0006Az-IK; Mon, 28 Oct 2024 06:36:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5N6o-0006Aj-GY for bug-guile@gnu.org; Mon, 28 Oct 2024 06:36:26 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t5N6o-0008NG-5A for bug-guile@gnu.org; Mon, 28 Oct 2024 06:36:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=tGT2o/5dvLY4YiUkRtRCCwOu2ewNJ5fwH0PXe5mLzww=; b=YYE3I2WjyhANS9y7bQy8eMD1cAvcWLvK66KWHxcx3q6bPoT+N7sqwe1qoypqlmdEDFnb7yQ0cc0Lek45yWo5F4+xuO9eqjDoxUeOPGGM6+M+2Z/jgnbaKPYA9IqGmS0U5Fcfid4GQypmQtdA8H1lpAazVI7cv4g8YR4VqJJxdeFmxmXpW2Dl3OUKaNElq70hMRQJqAmEizExJ9zZE/IJJEMxWoNCS+Ae8FVlizqDuOrcAEQufaOf6F0RY+if/lGxyRX3jTSY7cSTiTvllK1TPXiF5Xk6poinA+k/6B4rfoP5gH9UC27FuIReT2R9q+vNcgBnVOwIXvrB4+PdWKvN0w==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t5N7O-0000cd-3D for bug-guile@gnu.org; Mon, 28 Oct 2024 06:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 28 Oct 2024 10:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71684 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch Original-Received: via spool by 71684-submit@debbugs.gnu.org id=B71684.17301118152374 (code B ref 71684); Mon, 28 Oct 2024 10:37:02 +0000 Original-Received: (at 71684) by debbugs.gnu.org; 28 Oct 2024 10:36:55 +0000 Original-Received: from localhost ([127.0.0.1]:52663 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t5N7G-0000cD-ED for submit@debbugs.gnu.org; Mon, 28 Oct 2024 06:36:54 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:40960) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t5N7E-0000bv-67 for 71684@debbugs.gnu.org; Mon, 28 Oct 2024 06:36:53 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5N4P-0007vf-VV; Mon, 28 Oct 2024 06:33:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=tGT2o/5dvLY4YiUkRtRCCwOu2ewNJ5fwH0PXe5mLzww=; b=Wa4SkDVvB/WR/dNp8ehD O5fXqRIKy0bTtHPaAWcMsneBeV6vzYwN+0WjR38V1XSHOh1Ou8dhH82trlfiiBr5a+fsp65C5aAWl fGkyeRzokdEugj+XJehvx/Mz/AukMmF8OOb1PohXehkds30Ue1IHX1UkuSXUi0ql56RhSaBe5m237 /iI67jz+5+7ic4yEoLh8vzNcNoS7fzo+aDuAFsIW5m8XMhGDxfNaDO6her65tjotR4aCpSMcXe6DT Gn8FFqfKG6h4+2BSqbcWSwK1ldmqWpAk3pMoPNlnPq9mZG9pDNeh80OYvr9w4fkDv9MAdwMuF/N/c DuuOBiL/0ZcMXg==; In-Reply-To: <20240619114411.7302-1-janneke@gnu.org> (Janneke Nieuwenhuizen's message of "Wed, 19 Jun 2024 13:44:11 +0200") X-Url: http://AvatarAcademy.nl X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:11090 Archived-At: --=-=-= Content-Type: text/plain Janneke Nieuwenhuizen writes: With #71684 merged, this needs an update. New in this version: * document it! Greetings, Janneke --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=v2-0001-Add-peek-error-pke.patch Content-Transfer-Encoding: quoted-printable >From c0a856ac60a672db53d3ab7df8098a323fbb999a Mon Sep 17 00:00:00 2001 From: Janneke Nieuwenhuizen Date: Fri, 3 Mar 2023 11:26:34 +0100 Subject: [PATCH v2] Add peek-error, pke. Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=3DUTF-8 Debuging using `pk' is popular in Guile, but not really usable if the program is as (pseudo-)filter, i.e., writing its output to stdout. * module/ice-9/boot-9.scm (peek-error, pke): New procedures. * doc/ref/api-debug.texi (Simple Debugging): Document them. --- doc/ref/api-debug.texi | 13 ++++++++++--- module/ice-9/boot-9.scm | 10 ++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/ref/api-debug.texi b/doc/ref/api-debug.texi index ca5175b35c..35092fbdaf 100644 --- a/doc/ref/api-debug.texi +++ b/doc/ref/api-debug.texi @@ -34,9 +34,10 @@ covered in the rest of this section and elsewhere in thi= s manual (@pxref{Interactive Debugging}). Here we deal with a more primitive approach, commonly called ``print debugging,'' which is a quick way to diagnose simple errors by printing values during a program's execution. -Guile provides the @code{peek} procedure, more commonly known as -@code{pk} (pronounced by naming the letters), as a convenient and -powerful tool for this kind of debugging. +Guile provides the @code{peek} and @code{peek-error} procedures, more +commonly known as @code{pk} and @code{pke} respectively (pronounced by +naming the letters), as a convenient and powerful tool for this kind of +debugging. =20 @deffn {Scheme Procedure} peek stuff @dots{} @deffnx {Scheme Procedure} pk stuff @dots{} @@ -44,6 +45,12 @@ Print @var{stuff} to the current output port using @code= {write}. Return the last argument. @end deffn =20 +@deffn {Scheme Procedure} peek-error stuff @dots{} +@deffnx {Scheme Procedure} pke stuff @dots{} +Print @var{stuff} to the current error port using @code{write}. Return +the last argument. +@end deffn + @code{pk} improves on using @code{write} directly because it enables inspection of the state of code as it runs without breaking the normal code flow. It is also sometimes more practical than a full debugger diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 04f84215c9..4b611f6a9d 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -183,6 +183,16 @@ This is handy for tracing function calls, e.g.: =20 (define pk peek) =20 +(define (peek-error . stuff) + "Like PEEK (PK), writing to (CURRENT-ERROR-PORT)." + (newline (current-error-port)) + (display ";;; " (current-error-port)) + (write stuff (current-error-port)) + (newline (current-error-port)) + (car (last-pair stuff))) + +(define pke peek-error) + (define (warn . stuff) (newline (current-warning-port)) (display ";;; WARNING " (current-warning-port)) --=20 Janneke Nieuwenhuizen | GNU LilyPond https://LilyPond.org Freelance IT https://www.JoyOfSource.com | Avatar=C2=AE https://AvatarAcade= my.com --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 Janneke Nieuwenhuizen | GNU LilyPond https://LilyPond.org Freelance IT https://www.JoyOfSource.com | Avatar=C2=AE https://AvatarAcade= my.com --=-=-=--