GNU bug report logs - #58109
simple-format vs (ice-9 format) bug in 3.0.7?

Previous Next

Package: guile;

Reported by: Christopher Lam <christopher.lck <at> gmail.com>

Date: Tue, 27 Sep 2022 10:24:01 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 58109 in the body.
You can then email your comments to 58109 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#58109; Package guile. (Tue, 27 Sep 2022 10:24:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Christopher Lam <christopher.lck <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Tue, 27 Sep 2022 10:24:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Christopher Lam <christopher.lck <at> gmail.com>
To: bug-guile <at> gnu.org, guile-devel <guile-devel <at> gnu.org>
Subject: simple-format vs (ice-9 format) bug in 3.0.7?
Date: Tue, 27 Sep 2022 18:23:14 +0800
[Message part 1 (text/plain, inline)]
Hi guilers, here's a short bash session.
Why would the first bash call to "guile s.scm" work, but not the second one?
guile-3.0.7 on ubuntu.

============================
$ cat s.scm
(format #t "~f\n" 2.5)

$ guile s.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/chris/s.scm
;;; compiled
/home/chris/.cache/guile/ccache/3.0-LE-8-4.5/home/chris/s.scm.go
2.5

$ guile s.scm
Backtrace:
In ice-9/boot-9.scm:
  1752:10  6 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
           5 (apply-smob/0 #<thunk 7efd190d5540>)
In ice-9/boot-9.scm:
    724:2  4 (call-with-prompt ("prompt") #<procedure 7efd190e5760 …> …)
In ice-9/eval.scm:
    619:8  3 (_ #(#(#<directory (guile-user) 7efd190d9c80>)))
In ice-9/boot-9.scm:
   2835:4  2 (save-module-excursion #<procedure 7efd190c9150 at ice-…>)
  4380:12  1 (_)
In unknown file:
           0 (simple-format #t "~f\n" 2.5)

ERROR: In procedure simple-format:
In procedure simple-format: FORMAT: Unsupported format option ~f - use
(ice-9 format) instead

$ guile --version
guile (GNU Guile) 3.0.7
Packaged by Debian (3.0.7-deb+3.0.7-1)
Copyright (C) 2021 Free Software Foundation, Inc.

License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
============================
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#58109; Package guile. (Tue, 27 Sep 2022 10:36:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jean Abou Samra <jean <at> abou-samra.fr>
To: Christopher Lam <christopher.lck <at> gmail.com>, bug-guile <at> gnu.org,
 guile-devel <guile-devel <at> gnu.org>
Subject: Re: simple-format vs (ice-9 format) bug in 3.0.7?
Date: Tue, 27 Sep 2022 12:35:25 +0200

Le 27/09/2022 à 12:23, Christopher Lam a écrit :
> Hi guilers, here's a short bash session.
> Why would the first bash call to "guile s.scm" work, but not the 
> second one?
> guile-3.0.7 on ubuntu.
>


This is a duplicate of
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50059





Information forwarded to bug-guile <at> gnu.org:
bug#58109; Package guile. (Tue, 27 Sep 2022 10:39:02 GMT) Full text and rfc822 format available.

Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jean Abou Samra <jean <at> abou-samra.fr>
To: Christopher Lam <christopher.lck <at> gmail.com>, bug-guile <at> gnu.org,
 guile-devel <guile-devel <at> gnu.org>
Subject: Re: simple-format vs (ice-9 format) bug in 3.0.7?
Date: Tue, 27 Sep 2022 12:38:29 +0200

Le 27/09/2022 à 12:35, Jean Abou Samra a écrit :
>
>
> Le 27/09/2022 à 12:23, Christopher Lam a écrit :
>> Hi guilers, here's a short bash session.
>> Why would the first bash call to "guile s.scm" work, but not the 
>> second one?
>> guile-3.0.7 on ubuntu.
>>
>
>
> This is a duplicate of
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50059
>


Uh, at the end of module/ice-9/format.scm, there is

;; Thanks to Shuji Narazaki
(module-set! the-root-module 'format format)

which dates back to

commit 14469b7c69feb0f2c5b8a093f19fe2a548b31c5b
Author: Greg J. Badros <gjb <at> cs.washington.edu>
Date:   Thu Jan 20 20:58:30 2000 +0000

    * format.scm: Use (variable-set! (builtin-variable 'format)) to
    re-define format to be format:format (instead of just define,
    which interacts poorly with the module system).  Thanks to Shuji
    Narazaki for this change.

diff --git a/ice-9/format.scm b/ice-9/format.scm
index fce2737ce..40f20b3da 100644
--- a/ice-9/format.scm
+++ b/ice-9/format.scm
@@ -1670,7 +1670,9 @@

 (define format:abort (lambda () (error "error in format")))

-(define format format:format)
+;;(define format format:format)
+;; Thanks to Shuji Narazaki
+(variable-set! (builtin-variable 'format) format:format)

 ;; If this is not possible then a continuation is used to recover
 ;; properly from a format error. In this case format returns #f.



This probably predates #:replace and could be removed now, right?




Information forwarded to bug-guile <at> gnu.org:
bug#58109; Package guile. (Sat, 01 Oct 2022 13:41:01 GMT) Full text and rfc822 format available.

Message #14 received at 58109 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Jean Abou Samra <jean <at> abou-samra.fr>
Cc: christopher.lck <at> gmail.com, 58109 <at> debbugs.gnu.org, guile-devel <at> gnu.org
Subject: Re: bug#58109: simple-format vs (ice-9 format) bug in 3.0.7?
Date: Sat, 01 Oct 2022 15:40:18 +0200
Hi,

Jean Abou Samra <jean <at> abou-samra.fr> skribis:

> Uh, at the end of module/ice-9/format.scm, there is
>
> ;; Thanks to Shuji Narazaki
> (module-set! the-root-module 'format format)
>
> which dates back to
>
> commit 14469b7c69feb0f2c5b8a093f19fe2a548b31c5b
> Author: Greg J. Badros <gjb <at> cs.washington.edu>
> Date:   Thu Jan 20 20:58:30 2000 +0000

[...]

> This probably predates #:replace and could be removed now, right?

Yes, it could be removed, but probably not before the 4.0 series.

The ‘-Wformat’ warning introduced sometime in the 2.0 or 2.2 series
prepared for that removal by warning about simple-format/format
mismatches, but there’s probably still code out there that assumes
‘format’ is the full-blown ‘format’, even when (ice-9 format) is not
explicitly imported.

Thanks,
Ludo’.




Information forwarded to bug-guile <at> gnu.org:
bug#58109; Package guile. (Sat, 01 Oct 2022 14:15:02 GMT) Full text and rfc822 format available.

Message #17 received at 58109 <at> debbugs.gnu.org (full text, mbox):

From: Jean Abou Samra <jean <at> abou-samra.fr>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: christopher.lck <at> gmail.com, 58109 <at> debbugs.gnu.org, guile-devel <at> gnu.org
Subject: Re: bug#58109: simple-format vs (ice-9 format) bug in 3.0.7?
Date: Sat, 1 Oct 2022 16:14:17 +0200

Le 01/10/2022 à 15:40, Ludovic Courtès a écrit :
> Hi,
>
> Jean Abou Samra <jean <at> abou-samra.fr> skribis:
>
>> Uh, at the end of module/ice-9/format.scm, there is
>>
>> ;; Thanks to Shuji Narazaki
>> (module-set! the-root-module 'format format)
>>
>> which dates back to
>>
>> commit 14469b7c69feb0f2c5b8a093f19fe2a548b31c5b
>> Author: Greg J. Badros <gjb <at> cs.washington.edu>
>> Date:   Thu Jan 20 20:58:30 2000 +0000
> [...]
>
>> This probably predates #:replace and could be removed now, right?
> Yes, it could be removed, but probably not before the 4.0 series.
>
> The ‘-Wformat’ warning introduced sometime in the 2.0 or 2.2 series
> prepared for that removal by warning about simple-format/format
> mismatches, but there’s probably still code out there that assumes
> ‘format’ is the full-blown ‘format’, even when (ice-9 format) is not
> explicitly imported.



OK, understood. How about adding comments and documentation?

diff --git a/doc/ref/misc-modules.texi b/doc/ref/misc-modules.texi
index 6c899a905..2c00ed859 100644
--- a/doc/ref/misc-modules.texi
+++ b/doc/ref/misc-modules.texi
@@ -1122,6 +1122,13 @@ you try to use one of them.  The reason for two 
versions is that the
 full @code{format} is fairly large and requires some time to load.
 @code{simple-format} is often adequate too.

+Beware that when @code{(ice-9 format)} is loaded, it replaces the
+binding for @code{format} on the toplevel.  If your module loads
+another module that loads @code{(ice-9 format)}, then your module
+will see the @code{format} function from @code{(ice-9 format)},
+even if it does not itself import @code{(ice-9 format)}.  This is
+legacy behavior and may be removed in a future Guile version.
+

 @node File Tree Walk
 @section File Tree Walk
diff --git a/module/ice-9/format.scm b/module/ice-9/format.scm
index ee7cba910..026fd9b54 100644
--- a/module/ice-9/format.scm
+++ b/module/ice-9/format.scm
@@ -32,6 +32,8 @@
 (define-module (ice-9 format)
   #:autoload (ice-9 pretty-print) (pretty-print truncated-print)
   #:autoload (ice-9 i18n)         (%global-locale number->locale-string)
+  ;; Actually replaces the global format as soon as loaded; see the end
+  ;; of this file.
   #:replace (format))

 (define format:version "3.0")
@@ -83,7 +85,7 @@
   ;; format's user error handler

   (define (format-error . args)       ; never returns!
-    (with-throw-handler #t
+    (with-throw-handler #t
       (lambda ()
         (let ((port (current-error-port)))
           (unless (zero? %arg-pos)
@@ -1560,5 +1562,10 @@
           (close-port port)
           str)))))

-;; Thanks to Shuji Narazaki
+;; Set the format variable in the root module.  This is legacy and
+;; no longer necessary.  It means that as soon as (ice-9 format) is
+;; loaded somewhere by some module, the predefined binding for format
+;; becomes the extended format function, even in modules where (ice-9 
format)
+;; isn't imported.  Because of this, removing this line should be done
+;; when a backwards compatibility break is allowed.
 (module-set! the-root-module 'format format)




Best,
Jean





Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Wed, 12 Oct 2022 20:51:01 GMT) Full text and rfc822 format available.

Notification sent to Christopher Lam <christopher.lck <at> gmail.com>:
bug acknowledged by developer. (Wed, 12 Oct 2022 20:51:02 GMT) Full text and rfc822 format available.

Message #22 received at 58109-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Jean Abou Samra <jean <at> abou-samra.fr>
Cc: christopher.lck <at> gmail.com, 58109-done <at> debbugs.gnu.org, guile-devel <at> gnu.org
Subject: Re: bug#58109: simple-format vs (ice-9 format) bug in 3.0.7?
Date: Wed, 12 Oct 2022 22:50:03 +0200
Hi,

Jean Abou Samra <jean <at> abou-samra.fr> skribis:

> OK, understood. How about adding comments and documentation?

That’s a good idea.  Applied with minor tweaks and a commit log.

Thanks!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 10 Nov 2022 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 168 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.