Synsemadocsv0.6.xENES

Lenguaje

Módulos (use / export)

Dividí el código en archivos. export hace público un task/type/let/enum/routes; todo lo demás queda privado. Un módulo es un map de sus exports, importado bajo un alias.

El módulo — mathlib.syn:

export task square(n)
    give n * n

export let VERSION be "1.0"

task private_helper()        -- sin `export` → no visible para quien importa
    give 42

El entry que lo importa:

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")

Reglas§

export routes — grupos de rutas que un serve puede montar (mount)§

Un sitio grande no tiene que ser un solo bloque serve. Un módulo exporta un grupo de rutas; el entry lo monta (los cuerpos llaman a los helpers privados del módulo por nombre simple):

-- shop.syn
task fmt(n)                        -- privado
    give "$" + text(n)

export routes shop
    route "GET /shop"
        give html("<h1>" + fmt(99) + "</h1>")
    route "POST /shop/buy"
        expect body {item: text}
        give created(json of request)
-- app.syn
use "./shop.syn" as shop
serve on 8080
    mount shop.shop                -- o: mount shop.shop at "/store"

Los grupos aceptan solo entradas route (sin stream, sin rate_limit por ruta — errores claros); un requires auth montado sigue exigiendo auth with en el bloque serve, validado al construir el serve. Mirá Servidor HTTP y Construí un sitio web.