Subject: Re: bug#11293: format and simple-format confused after compiling

From: [email-masked] (Ludovic Courtès)
Date: Sun, 22 Apr 2012 01:30:04 +0200

Hi Aleix,

Aleix Conchillo Flaqué <[email-masked]> 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’.