ela

Compare

ela beside Bash, Python and Ruby.

The same things done in each language, where ela's ideas come from, and how fast ela runs beside Bash and Python. Each ela cell links its page in the manual.

1

The language

BashPythonRubyela
Running a programa line: git statussubprocess.run(["git", "status"])backticks, or system("git status")a line: git status (Commands)
Valuestext only, with arrays added onstr, int, list, dict and classeseverything an objecttext, numbers, booleans, lists, maps, structs, enums and null; no classes
Reading a variable$x, split into words and globbed unless quotedxx$x, never split or globbed; an unset one is an error (Variables)
A failed commandignored unless set -e, which has holesan exception when asked: check=Trueignored unless checkedstops the script with where and why; err = try cmd gives null or an Error with the exit code and stderr (Error handling)
Adding context to an errorby hand: echo "loading the site: $msg" >&2; exit 1raise SiteError("loading the site") from e, shown as two tracebacksraise SiteError, "loading the site" in a rescue, which sets causefail "loading the site", $err, which prints as one line, loading the site: reading config.toml: not found, and error.is($err, Error.NOT_FOUND) searches the chain (Errors as values)
Mistakes found before runningnone: a syntax error stops the script when its line is reachedsyntax, for the whole filesyntax, for the whole fileblock grammar, dropped results and an assignment to env, args or Type, before line 1; --lint finds more
Blocksif … fi, for … doneindentationendend, or end if, end for: a named end must match its block (Statements and blocks)
Choosing a valuecase … esac, setting the variable in every brancha dict: {"dir": "folder"}.get(kind, "file")case … when gives a valuelabel = switch $kind, a value from each case; for two, if $n == 1; "file" else "files" (Values from switch and if)
A list from a loopa loop that appends with +=: (( n % 2 == 0 )) && sq+=($((n * n)))a comprehension: [n * n for n in nums if n % 2 == 0]nums.select(&:even?).map { |n| n * n }the loop, on one line: sq = for n in $nums when $n % 2 == 0; $n * $n (Lists from for)
Joining text"$a$b"+, f-strings+, "#{a}"interpolation, "${a}${b}"; + is arithmetic, and on text an error (Strings)
Scoped settingsa subshell, localwithblocks: Dir.chdir(dir) { … }with dir "build", env.X = "1", put back however the block is left
Cleanuptrap … EXITtry … finallyensuredefer
Background work& and wait; a job can outlive the scriptsubprocess.Popen, threads, asynciospawn and Process.wait, threadsrun and wait; a proc or a with block waits for the jobs it started (Process control)
Asking the userread -p "Name? " name; select for a numbered menuinput("Name? "); a menu by handprint "Name? ", then gets.chomp; a menu by handask.yes("Delete 3 files?"), ask.choose("Deploy to?", $targets), read from the terminal even when stdin is a pipe (Asking the user)
A glob with no matchpassed on as the pattern's text, unless shopt -s failglobthe glob module gives an empty listDir.glob gives an empty listan error, as in zsh and fish (Strict rules)
Errorstersetracebackstracebacksmessages that say what to write instead, and --explain for each (Error messages)
Built-in datanonea large standard librarya large standard libraryJSON, TOML, YAML, CSV, tables, the keyring, hashes and files, built in
JSON to a tablejq -r '.data.orders[] | [.id, .customer.city] | @tsv', then a while read loop over the lines; a missing key an empty fieldpandas: pd.json_normalize(json.loads(body)["data"]["orders"]), a nested key a column such as customer.city; a missing one NaNJSON.parse(body).dig("data", "orders"), then map each order to an array by handt = json.table($body, at = "data.orders"); a nested value a column by its path, columns = {"city": "customer.city"}, and a row without it an error naming the row (Tables from JSON)
StyleanythingPEP 8, by conventionby conventionone layout from --fmt; --lint warns of a name off the naming style
2

Where the ideas come from

In elaFrom
A command is a line; pipes; $( ) captures outputBash
Lists, maps and the other types of value; with for a change the block puts backPython
Blocks closed by end, which may name its block: end ifRuby and Lua; the named end from Ada
defer, procs, and ..$xs to spread a list into a callGo and Odin
Errors as values, each wrapping its cause with what was being done: fail "loading the site", $errGo
Errors that say what to write insteadRust and Elm
A glob that matches nothing is an errorzsh and fish
3

Speed

ela gains most where Bash starts a program for a small job. Reading the modes of 1,000 files takes Bash 2.7 s, because it starts stat for each one; ela takes 4.7 ms, because it reads them itself, and Python 20 ms. ela also starts faster than Bash, and ten times faster than Python. JSON goes into a table without a tree in between: json.table makes a table of five columns from 200,000 orders, 45 MB of JSON, in 0.17 s and 61 MB of memory at the peak, 45 MB of it the text itself. The same table through json.decode, tree.pick and table.of takes 0.68 s and 675 MB. Both were measured on the same machine and build. It trails in two places. Python runs a tight loop over numbers about 3.5 times faster than ela, which is why the translation check below is two and a half times faster in its original Python. And a loop in ela over work the original handed to a C program runs slower: a walk over text one character at a time, which Bash gave to a single awk, takes eight times as long in ela. Faster loops are next in ela's plans.

The house's scripts, moved to ela

The scripts that build and check this project's repositories, each beside its port to ela, on the same input: the median wall time of seven runs. The ports ran on ela's build at commit 124b88d.

The jobOriginalOriginal msela ms
Check a library's cheat sheet against its API indexsh304123
Check a website's images and videosBash49018
Check a program's source strings against its translation cataloguesPython169430
Write an API index of a library's packages, from odin docsh717739
Find the calls in a program's Odin source that open a path to classify it, a character at a timeBash1321,067

Three small measurements

Each is the median of five runs, timed by bench.ela below, on one machine, an Intel Core i7-13700K, under nice beside other work, with Bash 5.2, Python 3.15 and ela built for release from commit 124b88d. A cell is the middle of three such runs. The figures compare the three on that machine; a start-up of a few milliseconds moves by a few tenths between runs.

The jobBash msPython msela ms
Start-up: bash -c '', python3 -c '', ela -c ''2.616.21.6
1,000 file modes: modes.sh, modes.py, modes.ela2,72819.84.7
1,000,000 additions: sum.sh, sum.py, sum.ela1,38762.9216
modes.sh
for i in {1..1000}; do    m=$(stat -c %a f)done
modes.py
import os for i in range(1000):    m = os.stat("f").st_mode & 0o7777
modes.ela
for i in range(1000)    m = file.mode("f")end for
sum.sh
n=0for ((i = 0; i < 1000000; i++)); do    ((n += i))doneecho $n
sum.py
n = 0for i in range(1000000):    n += iprint(n)
sum.ela
n = 0for i in range(1000000)    n = $n + $iend forecho $n
bench.ela
# Each case's commands, run turn about five times; the median wall time of each, in ms.# Run it beside the six scripts and an empty file f: ELA=$(command -v ela) ela bench.elaELA :: $env.ELACASES :: [    ["start-up", ["bash", "-c", ""], ["python3", "-c", ""], [$ELA, "-c", ""]],    ["1,000 file modes", ["bash", "modes.sh"], ["python3", "modes.py"], [$ELA, "modes.ela"]],    ["1,000,000 additions", ["bash", "sum.sh"], ["python3", "sum.py"], [$ELA, "sum.ela"]],] proc timed(cmd: list) -> number    t = time.now()    $cmd > /dev/null    return time.since($t) * 1000end proc proc median(xs: list) -> number    s = list.sort($xs)    return int($s[len($s) // 2] * 10) / 10end proc for c in $CASES    b = []    p = []    e = []    for round in range(5)        b = list.append($b, timed($c[1]))        p = list.append($p, timed($c[2]))        e = list.append($e, timed($c[3]))    end for    mb = median($b)    mp = median($p)    me = median($e)    echo "$c[0]: bash $mb ms, python $mp ms, ela $me ms"end for