ISO printf
printf
eprintf
sprintf
fprintf
8.12

ISO printf🔗ℹ

Bogdan Popa <bogdan@defn.io>

This module provides implementations of the ISO standard C printf family of procedures, based on their description in the OpenBSD manual.

procedure

(printf fmt arg ...)  void?

  fmt : string?
  arg : any/c
Prints the args to standard output according to the format string fmt.

The %n directive is not currently supported. The %q directive prints the eq-hash-code of a value in hex format. Directives typically fail gracefully on invalid or missing input, but malformed format strings may raise an error (eg. specifying a precision value twice).

Examples:
> (require iso-printf)
> (printf "hello\n")

hello

> (printf "%03d\n" 1)

001

> (printf "%04hd %04hd\n" 32767 16777215)

32767 -001

> (printf "%0*.*f\n" 12 3 1234567.89)

01234567.890

> (printf "%+.9g\n" 1234.456789)

+1234.45679

procedure

(eprintf fmt arg ...)  void?

  fmt : string?
  arg : any/c
Prints the args to standard error according to the format string fmt.

procedure

(sprintf fmt arg ...)  string?

  fmt : string?
  arg : any/c
Constructs a string by interpreting fmt against the given args.

procedure

(fprintf out fmt arg ...)  void?

  out : output-port?
  fmt : string?
  arg : any/c
Prints the args to out according to the format string fmt.