Import std.core.format
std.core.format
Formatting by a template the program has only when it runs, and the debug form.
Formatting by a template that the program has only when it runs: Format, whose fields take interpolation's specs, which the runtime splits; and the debug form, "{x:?}", which the compiler makes for every type, and Dump.
std/core/format.fb
Types
DebugElements
attribute
Public Attribute DebugElements
On an Iterable type, makes its debug form show its elements in place of its Fields, as
"Stack<Int32> [1, 2]".
DebugEntries
attribute
Public Attribute DebugEntries
On an Iterable type of (key, value) tuples, makes its debug form show them as a Map's, as
"Map<String, Int32> {"a": 1}".
Functions
Format
function
Public Function Format(template: String, values: Formattable...): String Throws FormatError
template with its fields filled: "{}" is the next value, "{0}" the first, and either can
take a format spec after a ':', as "{0:>8}" or "{:.2}" does, or else shows its value as "{x}"
does; "{{" and "}}" are braces. In source, a template is a raw string, r"{} of {}", whose
braces aren't interpolations. Throws a FormatError for a template that isn't one, a field
whose value isn't given, or a spec that its value doesn't take.
Examples
Local line = Try Format(r"{} has {} points", "Ada", 36)
Expect(line == "Ada has 36 points")
Local swapped = Try Format(r"{1}, {0}", "a", "b")
Expect(swapped == "b, a")
Local padded = Try Format(r"[{0:>5}]", 42)
Expect(padded == "[ 42]")
Dump
function
Public Function Dump<T>(value: T): String
The debug form of value, with each part on a line of its own, as "{value:#?}" gives it.
Examples
Struct Point
Field X: Int
Field Y: Int
End Struct
Local shown = Dump(Point(1, 2))
Expect(shown.Contains("X") && shown.Contains("1") && shown.Contains("\n"))Report an issue with this page or with FutureBlitz on GitHub.