On this page:
22.1 Conventional Formatting Procedures
format-symbol-for-display
indent-lines
join-lines
join-lines*
22.2 Message Formatting
message-formatter/  c
message-formatter
define-message-formatter
define+  provide-message-formatter
combine-message-formatters
default-message-formatter
current-message-formatter
format-message
8.12

22 Formatting🔗ℹ

 (require denxi/format) package: denxi

denxi/format provides all bindings from racket/format, including the below bindings.

22.1 Conventional Formatting Procedures🔗ℹ

procedure

(format-symbol-for-display sym)  string?

  sym : symbol?
Like symbol->string, except the resulting string wraps the symbol’s string content in conventional quotes for display in human-readable output.

procedure

(indent-lines lines)  (listof string?)

  lines : (listof string?)
Returns a new version of lines where each element has two leading spaces.

procedure

(join-lines [#:trailing? trailing?]    
  #:suffix suffix    
  lines)  string?
  trailing? : any/c = #f
  suffix : (or/c char? string? #f)
  lines : (listof string?)
Combines lines into a single string.

If suffix is #f, then join-lines will use a platform-specific suffix.

If trailing? is #t, then the last line will also end in the suffix.

procedure

(join-lines* [#:trailing? trailing?]    
  #:suffix suffix    
  line ...)  string?
  trailing? : any/c = #f
  suffix : (or/c char? string? #f)
  line : string?
Like join-lines, except lines are accumulated from formal arguments.

22.2 Message Formatting🔗ℹ

Messages are useful for exchanging information without formatting concerns, but program output must include human-readable strings. This section therefore defines a message formatter as a procedure that translates a message to a string. The bindings documented in this section pertain exclusively to message formatters.

A contract that matches a message formatter.

syntax

(message-formatter patts ...)

Expands to (λ (m) (match m patts ...)).

(define-message $foo (a b c))
 
; "1 2 3"
((message-formatter [($foo x y z) (format "~a ~a ~a" x y z)]) ($foo 1 2 3))

syntax

(define-message-formatter id patts ...)

Expands to (define id (message-formatter patts ...))

syntax

(define+provide-message-formatter id patts ...)

Expands to

(begin (provide (contract-out [id message-formatter/c]))
       (define-message-formatter id patts ...))

procedure

(combine-message-formatters formatter ...)  message-formatter/c

  formatter : message-formatter/c
Returns a message formatter that uses each formatter in the order passed.

A message formatter useful only for producing locale-independent fallback strings.

A parameter holding the message formatter for use with format-message.

procedure

(format-message m)  string?

  m : $message?
Equivalent to ((current-message-formatter) m).