export
The export keyword exposes an element, introduced inside a module, outside the module. This keyword operates with the
keyword import as its counterpart.
The export statement is only valid inside modules. Exported values behave as compile-time constants in the importing
script. Exported values and exported tables therefore must resolve to
compile-time constants, which excludes runtime-built values such as ranvar,
zedfunc, and embedding in those exports. Exported functions and exported schemas may still return or declare those types.
export scalar value
A scalar value can be exported:
// Module "/sample/my-module"
export const myHello = "Hello"
Then, it can be imported:
import "/sample/my-module" as M with
myHello
show scalar "" with myHello
export tuple value
A tuple can be exported when all its elements are compile-time constants:
// Module "/sample/settings"
export const config = ("EUR", 2)
The importing script can unpack the tuple into constants:
import "/sample/settings" as Settings
const currency, digits = Settings.config
show summary "Settings" a1d2 with
currency
digits
The tile shows “EUR” and 2.
export user-defined function
A user-defined function can be exported:
// Module "/sample/my-module"
export def pure plusOne(x: number) with
return x + 1
Then, it can be imported:
import "/sample/my-module" as M with
plusOne
show scalar "" with plusOne(2) // 3
Vector functions can also be exported with export def vector; see
exporting a vector function
for a module and its importing script.
export inline enums
An enum can be exported:
// Module "sample/my-module"
export table enum E = "A", "B"
Then, it can be imported:
import "/sample/my-module" as M with
E
a = enum<<E>>("A")
show scalar "" with text(a)
export table comprehension
A table comprehension can be exported:
// Module "/sample/my-module"
export table T = with
[| as A, as B |]
[| 1, true |]
[| 2, false |]
[| 4, true |]
Then, it can be imported:
import "/sample/my-module" as M with
T
show table "" with T.A, T.B
export path schema
A path schema can be exported:
// Module "/sample/my-module"
export schema '/sample/products.csv' with
Product : text
Color : text
Price : number
Exported schemas may also declare ranvar, zedfunc, and embedding fields,
subject to the usual file-format restrictions when the schema is used.
When a module is imported, all the path schemas that it exports are automatically imported as well.
import "/sample/my-module" as M
read '/sample/products.csv' as Products
show table "My Products" with
Products.Product
Products.Color
Products.Price
export named schema
A named schema can be exported:
// Module "/sample/my-module"
export schema Products with
Product : text
Color : text
Price : number
Then, it can be imported:
import "/sample/my-module" as M
read "/sample/products.csv" as Products with
schema M.Products
show table "My Products" with
Products.Product
Products.Color
Products.Price