1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00
Commit graph

30 commits

Author SHA1 Message Date
Michael Käppler
80d4055e42
Fix error messages containing format strings
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>
2024-05-06 11:51:53 +02:00
Jean Abou Samra
bc3b1a4e2d doc: Document how (ice-9 format) replaces 'format'.
* doc/ref/misc-modules.texi (Formatted Output): Add paragraph.
* module/ice-9/format.scm: Add comment.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2022-10-12 22:49:00 +02:00
Timothy Sample
c85724bd0a (ice-9 format): Fix scaling floats with leading zeros 2021-10-19 02:52:15 +02:00
Andy Wingo
b16ad94667 More format refactorings.
* 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.
2019-08-13 23:08:46 +02:00
Andy Wingo
687981feeb More format refactors
* module/ice-9/format.scm (format): Flatten all internal definitions,
  except format-work.
2019-08-13 22:46:32 +02:00
Andy Wingo
a2aec7157c More format refactors
* module/ice-9/format.scm (format): Use internal defines rather than
  letrec, to prevent things from creeping rightwards so much.
2019-08-13 22:33:32 +02:00
Andy Wingo
077ba996e8 Refactor `format' to use when/unless conventionally
* module/ice-9/format.scm (format): Update to make one-armed ifs use
  when/unless.
2019-08-13 22:22:42 +02:00
Andy Wingo
c248ea10be Remove all deprecated code
* module/ice-9/debug.scm:
* module/ice-9/mapping.scm:
* module/ice-9/syncase.scm: Delete these deprecated files.
* module/Makefile.am: Remove deleted files.
* libguile/deprecated.c:
* libguile/deprecated.h:
* libguile/backtrace.c:
* libguile/goops.c:
* libguile/numbers.c:
* libguile/socket.c:
* libguile/srfi-13.c:
* module/ice-9/deprecated.scm:
* module/ice-9/format.scm:
* module/oop/goops.scm:
* module/statprof.scm:
* module/texinfo/reflection.scm:
* module/web/client.scm:
* module/web/uri.scm: Remove deprecated code.
2017-05-22 13:36:42 +02:00
Mark H Weaver
6dce942c46 String ports use UTF-8; ignore %default-port-encoding.
* 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.
2013-08-07 01:22:22 -04:00
Ludovic Courtès
6c9220064d Micro-optimize (ice-9 format).
* module/ice-9/format.scm (format): Use `call-with-output-string'
  instead of `with-output-to-string'.
2012-08-21 00:36:50 +02:00
Ludovic Courtès
afd08fdf87 format: Add specifier ~h for localized number output.
* 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.
2012-02-03 16:35:06 +01:00
Ludovic Courtès
1497e87a4f Make `(format #f ...)' always Unicode-capable.
* 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.
2011-02-08 23:14:00 +01:00
Mark H Weaver
6a07a06118 Do not apply inf?' or nan?' to strings
* 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.
2011-01-28 12:16:59 +01:00
Andy Wingo
b90b4b2bf2 format handles ~@c better
* module/ice-9/format.scm (format): Fix ascii-ism in ~@c. Pull
  flush-output? into the let*.
2010-12-18 13:13:16 +01:00
Andy Wingo
79f124ac87 more format tweaks
* module/ice-9/format.scm (format): Strip format: prefix from port and
  output-col.
2010-12-18 13:02:07 +01:00
Andy Wingo
8390dac023 more format tweaks
* 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.
2010-12-18 12:57:29 +01:00
Andy Wingo
0e9306801a take advantage of letrec* in format
* module/ice-9/format.scm (format): Take advantage of letrec* internal
  expansion, and so have fewer set! invocations.
2010-12-18 12:50:00 +01:00
Andy Wingo
d55066ddc3 inline format:out into format
* module/ice-9/format.scm (format): Inline format:out into the body.
2010-12-18 12:42:50 +01:00
Andy Wingo
098e6fc63f more format cleanups
* 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.
2010-12-18 12:32:14 +01:00
Andy Wingo
f02f8a6174 format's first arg is "destination"
* module/ice-9/format.scm: The argument to format is "destination", not
  "port". Fix this newly reintroduced buglet.
2010-12-18 12:20:26 +01:00
Andy Wingo
3d56118c50 inline format:format into format
* module/ice-9/format.scm (format): Inline format:format body.
2010-12-18 12:17:46 +01:00
Andy Wingo
2ce77e6cf6 deprecate omission of port to ice-9 format
* 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.
2010-12-18 12:06:53 +01:00
Andy Wingo
29d096c8e6 letrec -> internal definitions in format.scm
* module/ice-9/format.scm (format): Change from letrec to internal
  definitions, and use the define (foo ...) .. shorthand. No semantic
  change.
2010-12-18 11:44:57 +01:00
Andy Wingo
9ebf1af3c1 format.scm cleanups
* 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.
2010-12-18 11:27:19 +01:00
Andy Wingo
e3e3394374 ice-9 format license update
* module/ice-9/format.scm: A more standard copyright header, with
  LGPLv3+ instead of public domain. Update define-module block.
2010-12-18 11:21:29 +01:00
Andy Wingo
c89920a71f deprecate passing a number as the destination to `format'
* module/ice-9/format.scm (format): Deprecate having a number as the
  destination.
* doc/ref/misc-modules.texi (Formatted Output): Update docs.
2010-08-28 13:44:00 -07:00
Andy Wingo
625b43acc7 fix `format' with %f and exact rationals
* 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.
2010-06-06 13:46:53 +02:00
Andy Wingo
9274c3dd40 ~:@y allows for truncation to an absolute maximum width
* 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.
2009-12-29 21:15:08 +01:00
Andy Wingo
b8596c08ac add ~@y truncated printing directive to format
* 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.
2009-12-29 13:29:02 +01:00
Andy Wingo
00d0489205 move ice-9/ and oop/ under module/
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.
2008-11-01 12:44:21 +01:00
Renamed from ice-9/format.scm (Browse further)