The builtin primitive procedure `error` takes an optional message and
a list of arguments to include into the error message.
These args are formatted with `~S` and appended to the error message, so
that an example call of
`(error "Wrong argument: " 42)`
results in the output
"Wrong argument: 42"
If format strings occur in the message itself, however, they are
escaped. Thus a call like
`(error "Wrong argument: ~a" 42)`
is rendered as
"Wrong argument: ~a 42"
Some callers did not take this behavior into account, leading to
confusing error messages.
Changing the behavior of `error` to be
both backwards-compatible and accept also format strings inside messages
is not straightforward, because it would have to handle escaped `~`
characters as well. Therefore, fix `error` call sites using format
strings to use `format` before calling out to `error`.
The following files are affected:
* module/ice-9/format.scm (format)
* module/ice-9/r6rs-libraries.scm (resolve-r6rs-interface)
* module/oop/goops.scm (make)
* module/srfi/srfi-37.scm (Comment at the beginning of file)
* module/system/base/compile.scm (call-once)
* module/system/repl/command.scm (break, tracepoint)
* module/system/repl/common.scm (repl-default-options)
* module/system/vm/traps.scm (arg-check, trap-at-source-location)
There are a couple of further call sites that were left unchanged,
either because they are using their own `error` procedure:
* module/ice-9/read.scm
* module/ice-9/command-line.scm
or are not referenced from other modules:
* module/system/base/lalr.upstream.scm:
* module/sxml/upstream/assert.scm:
* module/sxml/sxml-match.ss:
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
* module/ice-9/format.scm (format): Refactor naming of some local
variables. Assigned variables get a % sigil before them. Also, avoid
the mutable-error dance.
* libguile/strports.c (scm_mkstrport): Use UTF-8; ignore
%default-port-encoding. Rename 'str_len' and 'c_pos' to
'num_bytes' and 'c_byte_pos'. Interpret 'pos' argument
as a character index instead of a byte index.
* module/ice-9/boot-9.scm (%cond-expand-features): Add srfi-6 to the
list of core features.
* module/srfi/srfi-6.scm (open-input-string, open-output-string): Simply
re-export these, since the core versions are now compliant.
* doc/ref/api-io.texi (String Ports): Remove text that describes
non-compliant behavior of string ports with regard to encoding.
* doc/ref/srfi-modules.texi (SRFI-0): Add srfi-6 to the list of
core features.
(SRFI-6): Remove text that mentions non-compliant behavior of
core string ports.
* module/ice-9/format.scm (format):
* module/ice-9/pretty-print.scm (truncated-print):
* module/rnrs/io/ports.scm (open-string-input-port,
open-string-output-port):
* test-suite/test-suite/lib.scm (format-test-name):
* test-suite/tests/chars.test ("combining accent is pretty-printed",
"combining X is pretty-printed"):
* test-suite/tests/ecmascript.test (eread, eread/1):
* test-suite/tests/rdelim.test:
* test-suite/tests/reader.test (read-string):
* test-suite/tests/regexp.test:
* test-suite/tests/srfi-105.test (read-string): Don't set
%default-port-encoding before creating string ports.
* benchmark-suite/benchmarks/ports.bm (%latin1-port): Use
'set-port-encoding!' to set the string port encoding.
(%utf8/ascii-port, %utf8/wide-port, "rdelim"): Don't set
%default-port-encoding before creating string ports.
* test-suite/tests/r6rs-ports.test ("lookahead-u8 non-ASCII"): Don't set
%default-port-encoding before creating string ports.
("put-bytevector with UTF-16 string port", "put-bytevector with
wrong-encoding string port"): Use 'set-port-encoding!' to set the
string port encoding.
* test-suite/tests/print.test (tprint): Use 'set-port-encoding!' to set
the string port encoding.
("truncated-print"): Use 'pass-if-equal'.
* test-suite/tests/ports.test ("encoding failure leads to exception",
"%default-port-encoding is honored", "peek-char [latin-1]", "peek-char
[utf-8]", "peek-char [utf-16]"): Remove tests.
("%default-port-encoding is ignored", "peek-char"): Add tests.
("suitable encoding [latin-1]", "suitable encoding [latin-3]",
"wrong encoding, error", "wrong encoding, substitute",
"wrong encoding, escape"): Use 'set-port-encoding!' to set the
string port encoding.
("%default-port-encoding, wrong encoding"): Rewrite to use
a file port instead of a string port.
* doc/ref/misc-modules.texi (Formatted Output): Document ~h. Recommend
use of ~h instead of ~:d.
* module/ice-9/format.scm (format): Add support for ~h.
* test-suite/tests/format.test ("~h localized number"): New test prefix.
* test-suite/tests/i18n.test (%american-english-locale-name,
%american-english-locale): New variables.
(under-american-english-locale-or-unresolved): New procedure.
("format ~h"): New test prefix.
* module/ice-9/format.scm (format): When DESTINATION is #f, use a
Unicode-capable output string port.
* test-suite/tests/format.test ("format basic output")["default to
Unicode-capable port"]: New test.
* module/ice-9/format.scm (format): Test to make sure an argument is a
number before applying `inf?' and `nan?' to it. Formerly, format
would call `inf?' and `nan?' on arguments that might be either a
number or a string, although those predicates should ideally throw an
exception when applied to non-number objects.
* module/ice-9/format.scm (format): Move the port and output-col to let*
vars, again removing a set!. We will probably move more state vars to
the let*, to let the procedures exist in a more fixed-point style.
* module/ice-9/format.scm (format): Remove the need to save a copy of
the incoming arguments, because they are available as local
variables. Do the check early for the format-string actually being a
string.
* module/ice-9/format.scm (format): Add port and format-string as formal
arguments. Seems also to have triggered a reindent. Formally
deprecate omitting the port, as it's usually an error.
* test-suite/tests/format.test ("format basic output")
("format basic output", "~{ iteration"): Fix up tests that omitted the
destination port.
* module/ice-9/format.scm (format:symbol-case-conv)
(format:iobj-case-conv): Remove these exports, they were not used.
(format:expch): Remove this one, though it was used.
(format:floats, format:complex-numbers, format:radix-pref): Inline
these "configuration variables" into the format body.
* module/ice-9/format.scm (format:parse-float): Accept a number, and
when stringifying the number, first convert to inexact.
* test-suite/tests/format.test ("~f fixed-point"): Add exact rational
test.
* module/ice-9/format.scm (format): Allow ~:@y to interpret the width as
the maximum width, inclusive of whatever else has already been output.
* doc/ref/misc-modules.texi (Formatted Output): Document this.
* doc/ref/misc-modules.texi (Formatted Output): Add documentation for
the new ~@y format directive.
(Pretty Printing): Add documentation for truncated-write.
* module/ice-9/format.scm (format): Add ~@y, for doing a truncated
print. Also, allow both ~y variants to take a width parameter.
Moved ice-9/ and oop/ under module/, with the idea being that we have
only scheme under module/. Adjusted configure.in and Makefile.am
appropriately. Put oop/ at the end of the compilation order.