Home Documentation Templates Examples Showcase GitHub
Theme

Scripting · Reusable code

Imports & exports.

@import(path) executes an external Nift script in an isolated scope and imports only the bindings that script explicitly exports.

// scripts/math.nift
factor := 2
double := x => x * factor

export(double)
@import("scripts/math.nift")

<p>$[double(21)]</p>

The imported script cannot implicitly read bindings from its caller. export(name) exports the actual binding, not a value snapshot, so exported closures retain private state correctly. Closures capture script locals (use a lambda such as double := x => x * factor); named fn declarations resolve free names in the calling scope, matching ordinary template @fn semantics.

count := 0
increment := () => ++count

export(count)
export(increment)

Exports are validated and installed atomically. Exporting a missing name, exporting the same name twice, or colliding with an existing caller binding makes the import fail without partially changing the caller.

Completion

CompletionMeaning under @import
Fall throughSuccessful import; commit valid exports.
returnEarly successful completion; commit valid exports.
return valueError. Imports communicate programmatically through export().

Imported scripts participate in Nift's path-security and tracked dependency model, including applicable transitive imports.