Implemented by the self-hosted compiler. An f or F immediately before a string quote enables interpolation:
DIM value=12.3456
DIM count=42
PRINT f"The value is: {value:.2f}"
PRINT f"Count: {count:08d}; hex: {count:#08x}"
PRINT f"{{literal braces}} {count+1}"This prints 12.35, 00000042, 0x00002a, literal braces and 43 in the corresponding positions. Ordinary strings retain their existing behavior. Double a quote inside literal text using BASIL’s "" convention. Expressions inside fields can contain quoted strings, calls, qualified module names, indexing, record construction, nested f-strings and checked TRY calls.
Each field evaluates exactly once, from left to right. Formatting creates an owned STRING. Existing borrow checks and independent-value semantics apply; formatting cannot retain an element borrow or repair a conflicting mutation. If a field fails through a checked call, earlier owned interpolation results are destroyed before reaching the enclosing handler or propagating.
Specifications
A colon separates an expression from a static specification. The order follows Python’s common mini-language:
[[fill]align][sign][#][0][width][grouping][.precision][presentation]
| Part | Behavior |
|---|---|
<, >, ^ |
Left, right, center alignment; strings default left, numbers right |
= |
Numeric padding after the sign and base prefix |
| Fill | One Unicode scalar immediately before alignment, such as 🌟^10 |
+, -, space |
Numeric sign policy; minus-only is the default |
# |
Integer base prefix or retained decimal point/trailing precision zeros |
0 |
Numeric zero padding, preserving sign/base prefix |
| Width | Minimum output width in Unicode scalars, not bytes or graphemes |
,, _ |
Numeric grouping; commas for decimal, underscores also for other integer bases |
.precision |
STRING scalar limit; DOUBLE fractional digits for f, digits after the point for e, significant digits for g |
s |
STRING |
d, b, o, x, X |
INTEGER/unsigned decimal, binary, octal, lower/upper hexadecimal |
f, F, e, E, g, G, % |
Fixed, scientific, general, percentage numeric formatting |
INTEGER and unsigned values may also use floating presentations through the ordinary binary64 conversion. BOOLEAN with an empty specification produces True/False; a nonempty valid numeric specification formats 1/0. With no numeric presentation or precision, DOUBLE uses the language’s existing shortest-round-trip STR spelling, including its exponent thresholds and .0 convention. This spelling is not promised identical to Python’s str in every case.
Decimal precision rounding uses the exact binary64 value and nearest rounding with ties to even; it does not multiply a binary approximation by powers of ten before rounding. Default explicit floating precision is six; g precision zero means one significant digit. With a precision but no presentation, general formatting preserves the customary .0 in fixed notation and uses the corresponding Python-style scientific threshold. Nonfinite values use inf/nan, uppercase for uppercase presentations. Percentage formatting scales in binary64 before decimal formatting.
Invalid syntax, incompatible value/specification types, unsupported values, and width/precision above 1,000,000 are compile-time errors, including in unused functions. Nested quoted interpolation is scanned with an explicit depth limit of 64. There is no unchecked runtime formatting failure channel. Allocation failure remains fatal, as for other STRING construction.
Specifications are static. Nested dynamic width/precision fields, !s/!r/!a conversions, debug =, locale-sensitive n, and character c are not implemented. Nominal OPERATOR Display
supplies text before STRING modifiers are applied. Multiline formatted blocks
use f""" immediately followed by a newline and support the same checked specifications. A malformed or unsupported specification is rejected instead of silently ignored. Existing checked positional FORMAT(template,values) remains available with its original contract.