Synsema docsENES

Modules (use / export)

Split code across files. export makes a task/type/let/enum public; anything else stays private. A module is a map of its exports, imported under an alias.

The module — mathlib.syn:

export task square(n)
    give n * n

export let VERSION be "1.0"

task private_helper()        -- no `export` → not visible to importers
    give 42

The entry that imports it:

modules.syn
-- Doc example: modules (use / export). Imports ./mathlib.syn under the alias `math`.
intent: "doc example: modules"
use "./mathlib.syn" as math

print("math.square(5) = " + text(math.square(5)) + ",  VERSION " + math.VERSION)

test "import an exported task and let (private_helper is NOT visible)"
    assert_eq(math.square(5), 25)
    assert_eq(math.VERSION, "1.0")

Rules