格式化
Creates a formatted string with `§` placeholders.
Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.
Creates a formatted string with § placeholders.
Syntax: \"<template>\"(<args>...)
Category#
format
Related#
Examples#
radix/corpus/scriptum/scriptum.fab (canonical · keyword)#
Creates a formatted string with § placeholders.
# =============================================================================
# 格式化 — Creates a formatted string with `§` placeholders.
# =============================================================================
#
# What this teaches:
# • String template interpolation — `"template § and §"(arg1, arg2)` replaces
# `§` placeholders with positional arguments
# • Templates can contain any expression as an argument, not just variables
#
# Common mistakes:
# • Confusing `格式化` (template desugaring into function calls) with bare `§` interpolation outside of the template syntax.
#
# See also: 读取, 行
# =============================================================================
# 格式化 — string-template interpolation ("§" slots)
#
# "literal § more §"(arg1, arg2) -- each § replaced by the corresponding arg
#
# GRAMMAR:
# templateExpr :← stringLit '(' exprList ')'
#
# EXPECTED OUTPUT:
# Salve greeting, persona notice, and computed 求和 string.
main {
const string 名称 ← "Marcus"
const int aetas ← 30
# One slot
const string salutatio ← "Salve, §!"(名称)
print salutatio
# Multiple slots
const string notitia ← "§ habet annos §"(名称, aetas)
print notitia
# With an expression
const string 求和 ← "10 + 20 ← §"(10 + 20)
print 求和
}Expected output:
Salve, Marcus!
Marcus habet annos 30
10 + 20 ← 30