--- Begin Message ---
Subject: |
format and simple-format confused after compiling |
Date: |
Fri, 20 Apr 2012 23:43:46 -0700 |
Hi,
today I just got a weird issue (probably my fault). I'm trying to
write a very basic Guile cookbook for beginners, which is the ony
think I know in any case.
Anyway, I have this script:
#!/usr/bin/guile -s
!#
(simple-format #t "my first message with a new line~%")
(format #t "my first ~a message with a number ~d and a new line~%"
"formatted" 1)
If you execute it for the first time (or after being edited) it
returns the right thing:
;;; note: source file /home/aleix/src/guile/guile-cookbook/recipe-3/recipe-3.scm
;;; newer than compiled
/home/aleix/.cache/guile/ccache/2.0-LE-8-2.0/home/aleix/src/guile/guile-cookbook/recipe-3/recipe-3.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /home/aleix/src/guile/guile-cookbook/recipe-3/recipe-3.scm
;;; compiled
/home/aleix/.cache/guile/ccache/2.0-LE-8-2.0/home/aleix/src/guile/guile-cookbook/recipe-3/recipe-3.scm.go
my first message with a new line
my first formatted message with a number 1 and a new line
However, if I execute it a second time without modifying the file I get:
my first message with a new line
my first formattedBacktrace:
In ice-9/boot-9.scm:
157: 7 [catch #t #<catch-closure 1aee9c0> ...]
In unknown file:
?: 6 [apply-smob/1 #<catch-closure 1aee9c0>]
In ice-9/boot-9.scm:
63: 5 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
407: 4 [eval # #]
In ice-9/boot-9.scm:
2189: 3 [save-module-excursion #<procedure 1aed340 at
ice-9/boot-9.scm:3724:3 ()>]
3731: 2 [#<procedure 1aed340 at ice-9/boot-9.scm:3724:3 ()>]
In unknown file:
?: 1 [load-compiled/vm
"/home/aleix/.cache/guile/ccache/2.0-LE-8-2.0/home/aleix/src/guile/guile-cookbook/recipe-3/recipe-3.scm.go"]
?: 0 [simple-format #t ...]
ERROR: In procedure simple-format:
ERROR: In procedure simple-format: FORMAT: Unsupported format option
~d - use (ice-9 format) instead
It seems to me that simple-format is saved in the compiled file,
instead of format.
Is this normal? Did I do anything wrong? The other question I had is
that I did not include "(use-modules (ice-9 format))" and it seems
included by default:
Enter `,help' for help.
scheme@(guile-user)> format
$1 = #<procedure 26aaae0 at ice-9/format.scm:1612:9 (destination
format-string . args) | (deprecated-format-string-only)>
I'm running 2.0.5.90-c0580.
Thanks,
Aleix
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#11293: format and simple-format confused after compiling |
Date: |
Sun, 22 Apr 2012 01:30:04 +0200 |
User-agent: |
Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.93 (gnu/linux) |
Hi Aleix,
Aleix Conchillo Flaqué <address@hidden> skribis:
> However, if I execute it a second time without modifying the file I get:
>
> my first message with a new line
> my first formattedBacktrace:
> In ice-9/boot-9.scm:
> 157: 7 [catch #t #<catch-closure 1aee9c0> ...]
> In unknown file:
> ?: 6 [apply-smob/1 #<catch-closure 1aee9c0>]
> In ice-9/boot-9.scm:
> 63: 5 [call-with-prompt prompt0 ...]
> In ice-9/eval.scm:
> 407: 4 [eval # #]
> In ice-9/boot-9.scm:
> 2189: 3 [save-module-excursion #<procedure 1aed340 at
> ice-9/boot-9.scm:3724:3 ()>]
> 3731: 2 [#<procedure 1aed340 at ice-9/boot-9.scm:3724:3 ()>]
> In unknown file:
> ?: 1 [load-compiled/vm
> "/home/aleix/.cache/guile/ccache/2.0-LE-8-2.0/home/aleix/src/guile/guile-cookbook/recipe-3/recipe-3.scm.go"]
> ?: 0 [simple-format #t ...]
>
> ERROR: In procedure simple-format:
> ERROR: In procedure simple-format: FORMAT: Unsupported format option
> ~d - use (ice-9 format) instead
That’s because (ice-9 format) does this evil thing:
(module-set! the-root-module 'format format)
In the first run, since the compiler uses (ice-9 format), the global
‘format’ binding pointed to the (ice-9 format) one. However, in the
second run, the global ‘format’ binding pointed to ‘simple-format’,
hence the error.
Starting from Guile 2.0.5, the ‘format’ compiler warning reports such
problems:
scheme@(guile-user)> (format #f "~d" 2)
;;; <stdin>:1769:0: warning: "~d": unsupported format option ~d, use (ice-9
format) instead
The fix is to explicitly import (ice-9 format) in your module.
Closing this bug, let us know if anything else is wrong!
Thanks,
Ludo’.
--- End Message ---