Skip to content

FmtParam

An unbound interpolation in a Fmt.

A FmtValue already carries a value. A FmtParam carries only a name and a specification. What the hole means is up to the consumer of the sequence — a SQL statement binds it as a placeholder, for example. Fmt.format fills holes from its arguments.

FmtParam exposes the same formatting fields and pad method as FmtSpec. Calling it with new keyword options returns a new FmtParam naming the same parameter.

Constructor

FmtParam name …

Parameters

NameTypeDescription
name (Int | Sym)
:fill? FmtFill
:align? FmtAlign
:sign? FmtSign
:width? Int
:precision? Int
:alt? Bool
:kind? FmtKind
:source? Str Interpolation as written in source

Errors

Exception Condition
TypeError name is neither an Int nor a Sym

Example

let hole = FmtParam :user: width: 8
assert_eq $hole.name :user:
assert_eq $hole.width 8

Methods

(call) … -> FmtParam

Returns a new FmtParam naming the same parameter with the supplied options merged. Positional arguments are not accepted. The result is synthetic rather than source-derived, so its source is nil.

Parameters

NameTypeDescription
:fill? (FmtFill | nil) Padding fill
:align? (FmtAlign | nil) Alignment
:sign? (FmtSign | nil) Sign display
:width? (Int | nil) Minimum width in grapheme clusters
:precision? (Int | nil) Numeric precision or maximum graphemes
:alt? (Bool | nil) Enables alternate formatting
:kind? (FmtKind | nil) Representation kind

(eq) other

Two parameters are equal when they name the same parameter under the same specification and record the same source.

name() -> (Int | Sym)

The parameter named by this position, as an Int or a Sym.

source() -> (Str | nil)

The text the parameter was written as, or nil. A ${#...} in a t"..." records the whole interpolation, sigil and delimiters included.

let seq = t"a=${#0:>3}"
assert_eq $seq[1].source r"${#0:>3}"