Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

Imports

The common sugar form is:

import from "<source>" <name>

Import this name from this source. Imports do not re-export by default; use public when the imported name should be visible to consumers of your module. The retired private import marker is not valid.

From the standard library#

Norma modules are named norma:<module>.

import from "norma:console" console

main {
    print "ready"
}

From a local file#

A relative path imports a sibling module. No extension.

reader locale
faber convert --to en — English reader surface
import from "./auxilium" saluta

main {
    print "ready"
}
faber convert --to la — canonical Faber
importa ex "./auxilium" saluta

incipit {
    nota "ready"
}
faber convert --to th-TH — Thai
นำเข้า ออก "./auxilium" saluta

เริ่ม {
    บันทึก "ready"
}
faber convert --to zh-Hans — Simplified Chinese
导入 取自 "./auxilium" saluta

入口 {
    显示 "ready"
}
faber convert --to zh-Hant — Traditional Chinese
匯入 取自 "./auxilium" saluta

入口 {
    註記 "ready"
}
faber convert --to vi — Vietnamese
nhập từ "./auxilium" saluta

bắt_đầu {
    ghi_chú "ready"
}
faber convert --to ar — Arabic
استورد من "./auxilium" saluta

بداية {
    اعرض "ready"
}
faber convert --to hi — Hindi
आयात सेवन "./auxilium" saluta

आरंभ {
    दिखाओ "ready"
}

Importing a specific item#

The name after the source is the item, not the module — so you import exactly what you use.

import from "norma:text" text

main {
    print "ready"
}

Aliasing#

as renames on the way in.

reader locale
faber convert --to en — English reader surface
import from "./auxilium" saluta as greet

main {
    print "ready"
}
faber convert --to la — canonical Faber
importa ex "./auxilium" saluta ut greet

incipit {
    nota "ready"
}
faber convert --to th-TH — Thai
นำเข้า ออก "./auxilium" saluta ในชื่อ greet

เริ่ม {
    บันทึก "ready"
}
faber convert --to zh-Hans — Simplified Chinese
导入 取自 "./auxilium" saluta 作为 greet

入口 {
    显示 "ready"
}
faber convert --to zh-Hant — Traditional Chinese
匯入 取自 "./auxilium" saluta 作為 greet

入口 {
    註記 "ready"
}
faber convert --to vi — Vietnamese
nhập từ "./auxilium" saluta như greet

bắt_đầu {
    ghi_chú "ready"
}
faber convert --to ar — Arabic
استورد من "./auxilium" saluta كـ greet

بداية {
    اعرض "ready"
}
faber convert --to hi — Hindi
आयात सेवन "./auxilium" saluta रूपमें greet

आरंभ {
    दिखाओ "ready"
}

Useful when two modules export the same name, or when the original reads badly at the call site.

Re-exporting#

public imports and re-exports, so consumers of your module see the name too. Imports without it remain private to the current module.

import from "norma:text" public text

main {
    print "ready"
}

Use public only when you deliberately intend to widen your module's surface.

The braced record form#

An import can also be written as a record. The field names are spelled by the file's reader pack, so an English file writes from, visibility, name and as, and a Latin file writes from, visibility, name and as.

import { from = "norma:text", visibility = public, name = text, as = t }

A field word from another locale is refused by name: import { from = "norma:text" } in an English file is `PARSE050 wrong_locale_import_field`.

From the target language#

A target word before the specifier imports a module of the target language itself, by its own name and verbatim. The program then belongs to that target: faber build -t python emits import math as m, while every other target, faber run and a plain faber check refuse it with SEM017 import_target_bound.

import python "math" m

main {
    print m.pi
}

A value from such a module flows into a scalar cell such as f64 directly. Storing it into a list, map or other structural cell needs an explicit ↦; without one it is SEM010 import_conversion_required.

import python "math" m
import python "re" re

main {
    let f64 root ← m.sqrt(2.0)
    let list<string> words ← re.findall("[a-z]+", "a1b2") ↦ list<string>
    print root
    print words
}

At a glance#

FormEffect
import from "norma:console" consoleStandard library module
import from "./auxilium" salutaItem from a sibling file
import from "./auxilium" saluta as greet…bound under a different name
import from "norma:text" public textImported and re-exported
import python "math" m (en import python "math" m)Target-language module; Python builds only

Related: A program is a package for how modules let inside a package · Packages with Cista for dependency resolution