मुक्त
Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi pack; supporting prose may still be English.
Marks a closure as capture-free; the closure may not reference any enclosing local or parameter.
Aliases: libera
Syntax: <type> <name> ← (params) free [→ <type>] ∴ <expression>
Category#
function
Related#
Examples#
radix/corpus/libera/libera.fab (canonical · keyword)#
Marks a closure as capture-free; the closure may not reference any enclosing local or parameter.
# =============================================================================
# libera (reader: free) — explicit capture-free closure contract.
# =============================================================================
#
# What this teaches:
# • A marked closure uses only its own params, body locals, and statically
# resolved identities (builtins, module items)
# • `free` sits after the parameter list and before the return clause
#
# Common mistakes:
# • referencing an enclosing local or parameter from inside the marked
# closure — the compiler rejects it (see libera-reject.fab)
#
# See also: clausura, ∴, functio
# =============================================================================
main {
const _ dupla ← int x free ∴ x * 2
print dupla(5)
const _ summa ← (int a, int b) free → int ∴ a + b
print summa(2, 3)
}Expected output:
10
5
radix/corpus/libera/libera-reject.fab (supporting · reject)#
CL-5 reject harness: a free-marked closure may not capture an enclosing local or parameter.
# =============================================================================
# libera — capture reject (CL-5)
# =============================================================================
# This exemplum intentionally fails to compile. The sibling .expected file
# pins only the stable diagnostic identity, not paths or rendered prose.
main {
const int seed ← 2
const _ add ← int x free ∴ x + seed
print add(40)
}Expected: compilation rejects this example.