Expand

import

load file or library

<import> = import <bareword>

import my-module would do the following:

  1. find a file to load, in this case my-module.sy in the current directory
  2. check, if this file was already imported. If it was not, then:
    1. read and parse the file
    2. recursively load its imports
    3. execute commands in the global scope of this file, if any
  3. create my-module alias, 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" 
        }
    }
}