ela
Contents

ManualLanguage

Strict rules

In the terminalela --spec strict-rules

Ela refuses to guess. Each rule below is an error with a message that says what to write instead.

RuleError exampleWrite instead
Text and numbers never mix"5" + 1, "10" < 9, "5" == 5int($x) + 1
No + on strings"a" + "b""${a}${b}"
Conditions are booleansif $name, if 1if $name != "", if len($xs) > 0
and, or, not take booleans1 and truea comparison
Integers never wrap9223372036854775807 + 1a smaller number, or one written with a fraction, 9223372036854775807.0 + 1; float(...) of a whole number stays whole
Undefined variables$typodefine it first
A glob matches nothingls *.nopequote it to pass the text: ls '*.nope'
Missing map keys$m["nope"]has($m, "nope") first
null is stored, compared and passed on, nothing else$s.port + 1, "${v}", if $v when it is nullhas($s, "port") or $v != null first
Struct literals give every fieldP{x: 1} when P has two fieldsall fields
Every parameter gets one argumentdeploy(), deploy("a", target = "b")each parameter without a default, once, by position or by name
Named arguments name a parameterdeploy("a", retry = 5)a name the proc has: retries = 5
Named arguments come lastdeploy(retries = 5, "a")deploy("a", retries = 5)
Defaults after the parameters withoutproc f(a = 1, b)proc f(b, a = 1)
A variadic parameter is never named or defaultedproc f(xs: ..string = []), f(xs = "a")proc f(xs: ..string), f("a")
Positions stay inside$xs[5], $xs[-6:] on five items-min(n, len($xs)), or len first
_ holds nothingecho $_name the value to keep it
A built-in's result is keptlist.append($xs, 1) or str.upper($s) alone on a linexs = list.append($xs, 1), s = str.upper($s) (Results are kept)
The environment through env$HOME, export PATH = ...$env.HOME, env.PATH = ...
A proc sees no script variable$branch inside a proc, set by the scripta parameter: proc f(branch: string)
A constant is set onceENDED = [] after ENDED :: [...]another name
No backticks in a commandecho `date`echo $(date), or 'date' for the text
No Bash ${...} forms${NAME:-x}, ${#xs}, ${s%.txt}env.get("NAME", "x"), len($xs), str.trim_suffix($s, ".txt")
break and continue in a loopbreak outside for or whilereturn, or exit
  • Text is known before the run. ela --lint reports + between two strings and a field read on a string as the errors the run would give, where the script makes the value text: a string literal, $env.NAME, a constant declared as one, or a variable every assignment in its scope gives one. VERSION = "1.2" then "app-$VERSION.tar.gz" fails before any line runs; write "app-${VERSION}.tar.gz".
  • Values, not references. Assigning or passing a list, map or struct copies it. Changing a copy never changes the original. A loop's value is one too: for i, x in $xs changes an item with xs[$i]["n"] = 0, and ela --lint warns of a change to x that nothing after it reads.
  • A proc sees no script variable. It gets what it needs as parameters and gives back what it changes with return (What a proc sees).
  • Blocks don't create scopes. Variables set inside if, for and while stay visible after the block.
  • Declarations go at the top level and may be used before the line that declares them.
  • Every call names a proc. Before the first line runs, ela checks each call in the script, in its procs and in the files it imports: a proc no file declares (deploy() with no proc deploy), a package proc ela lacks (str.starts_with, where str.has_prefix is meant) and a proc an import lacks (git.clne) each stop the script there, with the message the call would give, so no line runs first. ela --check reports every one.
  • Division. // and % truncate towards zero, as in Go and Odin: -7 // 2 is -3, -7 % 2 is -1.
  • Command failures stop the script with the command's own exit code; a missing command exits with 127.
  • Commands are only found on PATH. A name without a slash never runs a file from the current directory, and relative PATH entries are skipped.