การเรนเดอร์th-TH

praefixum

Translation status: ภาษาไทย reader-locale proof. Code fences render through the th-TH pipeline; prose is canonical Latin.

Forces compile-time evaluation of an expression.

Syntax: praefixum(<expression>)

Category#

comptime

None.

Examples#

radix/corpus/praefixum/praefixum.fab (canonical · keyword)#

Forces compile-time evaluation of an expression.

# =============================================================================
# praefixum — Forces compile-time evaluation of an expression.
# =============================================================================
#
# What this teaches:
#   • Compile-time evaluation — `praefixum(expr)` folds expressions at compile time, enabling constant computation.
#   • Block evaluation — `praefixum { ... }` evaluates a block at compile time for complex constants like maps.
#
# Common mistakes:
#   • Confusing `praefixum` (compile-time evaluation) with `scriptum` (string formatting) or `∷` (type ascription).
#
# See also: (none)
# =============================================================================

# praefixum — compile-time constant evaluation
#
# praefixum(<expr>)   -- fold a single expression at compile time
# praefixum { … }      -- fold a block literal at compile time
#
# GRAMMAR:
#   constExpr :← 'praefixum' '(' expr ')'
#   constBlock :← 'praefixum' block
#
# EXPECTED OUTPUT:
#   pi/tau strings, computed day/hour/second counts, block-evaluated sum.

main {
    # Constant expression
    const _ pi  comptime(3.14159)
    const _ tau  comptime((2 ↦ float) * 3.14159)
    print "pi: §"(pi)
    print "tau: §"(tau)

    # Computation
    const _ diesanno  comptime(365)
    const _ horaeanno  comptime(365 * 24)
    const _ secundaanno  comptime(365 * 24 * 60 * 60)

    print "dies: §"(diesanno)
    print "horae: §"(horaeanno)
    print "secunda: §"(secundaanno)

    # Block
    const map<string, int> codices  comptime({
        "ok": 200,
        "creatum": 201,
        "noninventum": 404,
        "error": 500
    })

    print "codex rectus: §"(codices["ok"])
}

Expected output:

pi: 3.14159
tau: 6.28318
dies: 365
horae: 8760
secunda: 31536000
codex rectus: 200