import
load file or library
<import> = import <bareword>
import my-module would do the following:
- find a file to load, in this case
my-module.syin the current directory - check, if this file was already imported. If it was not, then:
- read and parse the file
- recursively load its imports
- execute commands in the global scope of this file, if any
- create
my-modulealias, so that all exported functions are accessable through this alias
All imports happen sequentially in the order of definition.
Each import has it's own scope for variables, there is no way to access variables outside of the file, where they are defined.
Example
servers.sy
$cache := {}
fn status $server {
if $server not in $cache {
$cache[$server] = ssh $server /bin/report-status
}
put $cache[$server]
}
check-core-servers.sy
import servers
$core := ["core-a", "core-b"]
fn main {
for $server in $core {
$status := servers status $server
if $status != "ok" {
log "Server $server has a bad health: $status"
}
}
}