Renderingen-US

forma

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Captured backtick templates for bound payloads.

Syntax: template(args)

Category#

template

Examples#

radix/corpus/literalia/forma.fab (canonical · literal)#

Captured backtick templates for bound payloads.

# =============================================================================
# forma — Captured backtick templates for bound payloads.
# =============================================================================
#
# What this teaches:
#   • backtick template syntax `template`(args) — captures template text and parameters into the builtin `forma` class
#   • indexed placeholders `§0` for repeated parameter references
#   • templates without holes for static text
#
# Common mistakes:
#   • Expecting template application to render the string inline — \`...\`(args) captures into a forma class, it does not interpolate into a string.
#
# See also: format, string
# =============================================================================

# Captured `forma` templates
#
# Backtick template application captures template text and parameters into the
# builtin `forma` class. It does not render holes into the template string.
#
# EXPECTED OUTPUT:
#   Raw template text lines showing preserved § holes.

main {
    const string tenantId ← "tenant-42"
    const string plan ← "pro"
    const forma q ← `
        select id, email, plan
        from accounts
        where tenant_id = §
          and plan = §
    `(tenantId, plan)
    print q.template
    const forma indexed ← `where tenant_id = §0 or parent_tenant_id = §0`(tenantId, tenantId)
    print indexed.template
    const forma bare ← `select 1`
    print bare.template
}

Expected output:

        select id, email, plan
        from accounts
        where tenant_id = §
          and plan = §

where tenant_id = §0 or parent_tenant_id = §0
select 1