ela
Contents

ManualLanguage

Files and imports

In the terminalela --spec files-and-imports

  • File extension: .ela.
  • Imports are single files, using Odin-style syntax.
  • The file name becomes the prefix for its procs.
import "git.ela"        # procs called as git.cloneimport g "git.ela"      # renamed: g.clone
  • The path is relative to the importing file, not to the directory ela runs in. A script run through a symbolic link, or a file imported through one, imports from the folder of the real file, the one path.script() names, so scripts/roots, a link to ../ela/roots.ela, imports what sits beside roots.ela.
  • A path that starts with lib: names a library, a file shared between scripts and searched for in the library folders, where a relative path never looks. The lib: path is the file's place under a folder, and stays inside it: .. and a leading / are errors.
import "lib:git.ela"          # git.ela in a library folder: git.cloneimport g "lib:git.ela"        # renamed, as any importimport "lib:k8s/apply.ela"    # k8s/apply.ela under a library folder: apply.runimport "steps.ela"            # beside this script, never in a library folder
  • The library folders are searched in this order, and the first that holds the file wins:

    FolderDefault
    each folder of $ELA_LIB, separated by : as PATH's arenone
    $XDG_DATA_HOME/ela/lib~/.local/share/ela/lib
    each folder of $XDG_DATA_DIRS with ela/lib added/usr/local/share/ela/lib, then /usr/share/ela/lib

    An empty or relative entry is skipped. ELA_LIB is set in login.ela (SHELL.md, Login shell), so every script started after a login finds the same libraries; cron and CI set it as any variable. A package ships its ela libraries into /usr/share/ela/lib.

  • A name no folder holds is an error that names the folders searched, in order: can't import lib:git.ela: none of ~/.local/share/ela/lib, /usr/local/share/ela/lib, /usr/share/ela/lib holds it. ela --doctor lists the folders that exist and how many .ela files each holds.

  • A library is imported as any file is: its own imports are relative to it, or lib:. A library is a file in a folder: ela has no versions of one and fetches none.

  • ela --check and ela --lint resolve every import, relative and lib:, the imported files' own among them, and report one that finds no file, or that takes a built-in package's name (import str "lib.ela"), at the script's import, before anything runs. A call to a proc an import doesn't have, git.clne(...), stops the script before its first line (Strict rules).

  • An imported file holds only procs, structs, enums, constants and imports, so importing it runs nothing. Anything else is an error that says to move the line into a proc. Its constants are worked out when it is imported, and one that would run a command ($( )) is an error.

  • An imported file runs on its own: its procs see its own declarations and constants, as every proc does (Procs). Its structs and enums are used inside it; what crosses over is what its procs take and return.

  • Imports go at the top level. A cycle (a.ela importing b.ela importing a.ela) is an error, and so is an import named like a built-in package: file, path, dir, list, map, str, re, url, time, json, csv, toml, yaml, table, tree, hash, rand, ask, keyring, ela, sys, chart, text, md, pdf, env or http.