modules
Modules are reusable Envision code blocks imported by scripts or other modules. Modules are not executable: they do not
produce dashboards and cannot contain read, write, or show statements.
Only exported elements are visible outside the module. Non-exported values remain local to the module.
Export and import
The export keyword marks elements that can be imported elsewhere. The import keyword loads those elements.
// Module "/sample/my-module"
export const myHello = "Hello"
export const myWorld = "World!"
import "/sample/my-module" as M with
myHello
myWorld
show scalar "" with "\{myHello} \{myWorld}"
When a module is imported without a with block, its elements are accessed through the module alias as a namespace.
import "/sample/my-module" as M
show scalar "" with "\{M.myHello} \{M.myWorld}"
Inline documentation
Triple-slash comments (///) immediately preceding an exported element are attached as inline documentation.
// Module "/sample/my-docs"
/// Greeting prefix.
export const myHello = "Hello"
Chained imports
A module can import another module. Circular dependencies are rejected.
// Module "/sample/my-base"
export const myNumber = 10
// Module "/sample/my-next"
import "/sample/my-base" as M
export const myNumber = 13 + M.myNumber
Type annotations on import
Import entries may re-specify types for clarity.
// Module "/sample/my-types"
export const myText = "Hello World!"
export const myNumber = 42
import "/sample/my-types" as M with
myText : text
myNumber : number
show summary "" with myText, myNumber
Export limitations
Only scalar values, user-defined functions, enums, table comprehensions, and schemas can be exported. Fat data types such
as ranvar, zedfunc, or embedding cannot be exported.