A block print of a home workshop: a red rolling tool chest, wrenches and pliers on a yellow pegboard, a workbench with a vise, a stool, a sleeping black and white cat, and posters reading Good Tools Brighter Days and A Better Tomorrow

A language is more than its compiler. What makes one pleasant to use, or not, is mostly the tools around it: what checks the code, what lays it out, what shows it, and what helps when it goes wrong. Rust shows how much that matters, with cargo, clippy, rustfmt, rustdoc and rust-analyzer.

This new series is about those tools. It starts with X_eTaL, my array language, whose tools have grown a lot this fall, for reading code (print, format, find), understanding it (explore, debug), writing it (edit) and checking it (check, test).

Then and now

In October, Array Languages #19 measured X_eTaL’s tools against Rust’s: what was built, what was planned, and what was still wanted. A debugger that could step backward was on the wanted list. It exists now, and so does an expression explorer that wasn’t on any list. The rest of this post goes through the tools in that order, reading and understanding first, since that is what I do most, each with the command that does it. They all read the same plain-ASCII source and print deterministic text, so they work as well for a coding agent as for me.

Print

X_eTaL is typed in ASCII and read as typography. Here is a small program, the mean of a list, as typed:

# the mean of a list
u:m_ean := { v -> ('+ r_/ v) / t_ally v }
scores := 3 1 4 1 5 9 2 6
u:m_ean scores

xetal render prints it drawn: u:m_ean as ᵘm̲ean, := as ←, / as ÷. That is the form every code block on this blog shows, colored by a small highlighter:

⍝ the mean of a list
ᵘm̲ean ← { v → ('+ r̲/ v) ÷ t̲ally v }
scores ← 3 1 4 1 5 9 2 6
ᵘm̲ean scores                                       ⍝ 3.875

The same command prints it as LaTeX with --latex, for papers, and --raw turns drawn text back into ASCII.

Results can be printed boxed, as APL2’s DISPLAY drew them, with --box, or in plain ASCII with --ascii for terminals without box characters. xetal diagram draws one line of a program as an SVG, with callouts anchored to its parts, for slides and posters. And xetal doc --out prints a whole program or library as a documentation site, as rustdoc does; it is also a cross-reference, under Find.

Macro expansion. X_eTaL has no keywords, and much of what it does is written by macros, so xetal expand prints a program as it is after expansion, as ordinary code, which is how you see what a macro wrote. In X_eTaL-ML, the Flow library’s ᶠˡᵒʷp̲ipe< writes a layer as data flow, left to right, each stage taking the one before as it, with ▹m naming a stage’s value for later ones. Here is a stable softmax:

"flow:" u̲se< "Flow"
z ← 1.0 2.0 3.0
@ ᶠˡᵒʷp̲ipe< c"z ▷ 'm̲ax r̲/ it ▹m ▷ e̲xp z − m ▹e ▷ e ÷ '+ r̲/ e"

It prints 0.0900 0.2447 0.6652, to four places. xetal expand shows what the macro made of it, a line per stage, with the names the macro chose for itself:

{ @ →
  g1:stage ← z
  m ← { @ →
    it ← g1:stage
    'm̲ax r̲/ it
  } @
  e ← e̲xp z − m
  g2:stage ← e ÷ '+ r̲/ e
  g2:stage
} @

Equations. The Equations library in X_eTaL-libraries goes the other way: it reads an equation written as a paper prints it, computes it, and prints it back as LaTeX. Here is a convolution layer of a CNN, the triple sum over input channels and the two axes of the filter, for two 4 × 4 pictures through one 2 × 2 × 2 filter:

"e:" u̲se< "Equations"
X ← 2 4 4 r̲eshape r̲ange 32
W ← 1 2 2 2 r̲eshape r̲ange 8
(C, Kh, Kw) ← (2, 2, 2)
(O, Ho, Wo) ← (1, 3, 3)
(Y, tex) ← "Y[o,h,w] | O Ho Wo" ᵉb̲oth< "sum c:=0..C - 1, sum r:=0..Kh - 1, sum s:=0..Kw - 1 | X[c,h+r,w+s] * W[o,c,r,s]"

One call gives both the result, Y, and its LaTeX, tex:

Y_{o,h,w} = \sum_{c=0}^{C - 1} \sum_{r=0}^{Kh - 1} \sum_{s=0}^{Kw - 1} X_{c,h+r,w+s} \, W_{o,c,r,s}

which typesets as:

Y sub o, h, w equals the sum over c from 0 to C minus 1, over r from 0 to Kh minus 1 and over s from 0 to Kw minus 1, of X sub c, h plus r, w plus s, times W sub o, c, r, s Y sub o, h, w equals the sum over c from 0 to C minus 1, over r from 0 to Kh minus 1 and over s from 0 to Kw minus 1, of X sub c, h plus r, w plus s, times W sub o, c, r, s

Y is the 3 × 3 feature map 560 596 632, 704 740 776, 848 884 920, and the demo checks it against the library’s own cross-correlation. The ML demos draw their layers this way, the live pages typesetting the LaTeX beside the arrays: the Pipelines demo shows a CNN layer four ways, as a paper prints it, as a pipeline, as its expansion and as plain X_eTaL, all giving the same feature maps. The capability to produce mathematical expressions is part of what led to the name X_eTaL (LaTeX backwards).

Format

A blueprint drawing of a broom sweeping across a code window marked with angle brackets and a slash, dimensioned 64 by 54, labeled FRONT A blueprint drawing of a broom sweeping across a code window marked with angle brackets and a slash, dimensioned 64 by 54, labeled FRONT

xetal fmt prints a program’s canonical form, here the mean from Print: every application in parentheses, so there is no doubt about how it groups. X_eTaL reads right to left with no precedence, and the canonical form spells that out:

u:m_ean := { v -> (('+ r_/ v) / (t_ally v)) }
scores := 3 1 4 1 5 9 2 6
(u:m_ean scores)

That is the form to check against when a line doesn’t do what it seems to, and the form tools compare. It is not the form for reading; that is the drawn form.

Find

a brass spyglassFinding starts with the cross-reference. xetal doc builds a model of a program and everything it imports: every name linked to what it names (one of the program’s own items, an import, a system macro or a built-in), and every item to the places it is used. --out writes that model as a static site, with each file’s source drawn and every name a link, so reading code means following links; --json gives the same model to other tools. Its search finds an item by name or, as Haskell’s Hoogle does, by type. The reference site for X_eTaL’s built-ins and demos is built this way.

The hardest part of an array language is often not writing an expression but knowing which one to write. APL programmers have long kept idiom lists for that: a short expression for each everyday job. X_eTaL has one too, its idioms catalog, set beside five mainstream languages and the array languages X_eTaL descends from, and every X_eTaL entry in it is run by the test suite.

A list only helps if you know what to look for. The X_eTaL Idiom Finder is a web application I’ve just started, to search for idioms by what they do and run them on the spot. There is nothing to try yet; a future post in this series will show it.

Explore

A rectangular LED magnifier: a black handle with a switch, and a lens ringed with small white lights

An array expression does a lot in one line, and a debugger steps through it too coarsely to see why. The expression explorer shows it all at once: the expression typed as written beside its drawn form, run again whenever typing pauses, and every part listed with the value it had. Point at a part, with the mouse or the cursor, and it is marked in both forms, with its value, type and how many times it ran; choose a value, and it goes to the expression that made it. A tree view draws trains by their shape: fork, atop and hook.

It landed on December 2, as xetal explore in the terminal and as an Explore mode in the live demo, and it is still being developed.

Debug

An engraving-style drawing of an open electromechanical relay, its coil and contacts showing, as tweezers lift a moth out from between the contacts

X_eTaL’s debugger has three faces, all on one engine:

  • xetal dap serves the Debug Adapter Protocol, so VS Code, Emacs (dape) and Neovim (nvim-dap) can debug X_eTaL as they debug any language.
  • xetal debug FILE is a debugger in the terminal: the source with the stop and the breakpoints, the stack, the variables, watches and an array viewer.
  • The live demo has a Debug button, with the source drawn and colored.

Breakpoints can have a condition or a hit count. The array viewer shows a matrix as a grid, and a larger array a slice or a cube at a time. And it steps backward: Step Back and Reverse Continue run the program back to where a value went wrong, instead of starting over.

Edit

X_eTaL’s source is ASCII, so any editor can edit it. These make it pleasant:

  • xetal edit FILE, an editor in the terminal: the ASCII on the left, the drawn form on the right as you type, the types below, and keys to save and run.
  • The REPL, xetal repl, whose line editor draws the line as you type it, with history.
  • Emacs: xetal-mode colors the same classes the renderer does and, while the file keeps its ASCII, shows :=, ->, _l and _r as their glyphs and draws function names underlined, showing the one under the cursor as typed. Org Babel runs X_eTaL, below.
  • VS Code: an extension, for now for debugging (below).
  • The live demo: the browser editor shows the typed and drawn forms side by side, with completion, types as you edit, a notebook view that puts each result under the statement that printed it, and a library development view: a library and a program that uses it, edited and checked together, so a library can be written and tried at once.

a gnua gnuLiterate programming. X_eTaL comes with ob-xetal, Org Babel support, so an Org document can hold X_eTaL source blocks that Emacs runs, recording each block’s result under it. A block runs on its own, or continues the blocks above it that name the same :session, so a document builds a program up as it explains it. :seed fixes the random rolls, so results don’t change between runs; :echo yes shows each statement drawn, with its output under it; and :results file saves the picture a block draws, as an SVG, animated if it has frames. X_eTaL’s own literate documents, from a beginner’s introduction and the language tour to Life, the Towers of Hanoi and the combinator birds, are written this way. A script runs them all again in a batch Emacs, draws each block’s rendered form above it, and fails the build when a recorded result or picture is out of date, so the documents stay true to the language as it changes.

Check

A block print of a clipboard checklist: two items checked, one crossed out, and two boxes still empty

The first check is the type checker. It runs before any program does, and xetal type shows what it inferred for each top-level name, here for the mean from Print:

u:m_ean : Int -> Float
scores : Int

The second is xetal lint, built after Rust’s clippy: 36 named lints in groups (correctness, suspicious, style, complexity, pedantic, deprecated), each with a default level that a flag or a # lint: comment can change. Here is a small file with three things wrong with it:

ᵘs̲um ← { v → '+ r̲/ v }
ᵘl̲og ← { x → _ ← p̲rint! x◆ x }
Total! ← 0
warning[missing-bang]: function `u:l_og` calls `p_rint!`, an effect,
    but its name has no `!`: write `u:l_og!`
warning[global-mutable]: `Total!` is a global that changes: keep the state
    in a function, or `# lint: allow global-mutable` where a global is the point
warning[mutable-constant]: `Total!` is mutable but named like a constant: write `total!`

xetal lint --explain missing-bang says what a lint checks, why, and gives an example. xetal lint --fix makes the fixes that are sure, here renaming ᵘl̲og to ᵘl̲og! and Total! to total!, and reports what is left: the global, which is a choice only I can make. --format json gives one finding a line, for editors.

Test

A symmetrical black inkblot, a Rorschach test card, on creased, aged paper

The checker and the linter look at code without running it. Tests run it, and X_eTaL has three kinds today.

Doc tests. A doc comment can carry an example, a ## >> line, with what it prints below it, and xetal doc --test runs every one and compares, as cargo test runs Rust’s doc tests. The documentation’s examples can’t go stale, because a wrong one fails:

## u:m_ean v: the arithmetic mean of a list.
## >> u:m_ean 1 2 3 4
## 2.5
u:m_ean := { v -> ('+ r_/ v) / t_ally v }
doc tests in mean.xtl: 1 example
(file) >> u:m_ean 1 2 3 4 ... ok
doc test result: ok. 1 passed; 0 failed

Change the 2.5 to 2.6, and it reports the expected and the actual output, error[doc-test-failed], and a failing exit status.

Assertions. The Check library in X_eTaL-libraries has assertions that report as text, for tests and for teaching, and a macro for table-driven checks, each named by its own source.

Golden baselines. X_eTaL’s own test suite and the libraries in X_eTaL-libraries check programs against recorded output and types: run a program, compare what it prints, and fail on any difference. The language’s spec is a set of such cases, so a change in behavior shows up as a diff.

What X_eTaL doesn’t have yet is a unit test runner of its own. That is planned; see what comes next.

What comes next

a question mark

I’m refining the earlier tools before going much further with new ones. After that, these are planned, grouped by the title’s verbs, reading first. That is the order of importance, not of delivery: installers and a package manager may well come sooner.

a magnifying glass Read it: larger programs
  • A pretty printer that lays out long programs, and a cross-reference for a whole project rather than a program and its imports.
a quill pen Write it: start a project, and editors and IDEs
  • xetal new and a project manifest, as cargo new and Cargo.toml are for Rust: a command that lays out a new project, and a file naming its libraries, their versions and its settings, which the package manager reads. The manifest is planned in .xtln, X_eTaL notation, which landed this week: a strict subset of X_eTaL that holds data only, with no calls, definitions, imports or macros, so reading a file can’t run anything. It keeps what JSON loses, such as element types, shapes and the kind of an empty array, and X_eTaL already converts it to and from JSON, TOML and YAML. It does for X_eTaL what TOML does for Cargo.
  • xetal lsp, a language server beside xetal dap, built from what exists: diagnostics from the checker and the linter, quick fixes from lint --fix, hover with types and docs, completion, go to definition and references from the xetal doc model, formatting from xetal fmt, and the drawn form as inlay hints.
  • Editors as clients of both servers: Emacs (eglot and dape), JetBrains IDEs such as IntelliJ IDEA and RustRover (through LSP4IJ, then perhaps a plugin of its own), a Zed extension, and the VS Code extension gaining the language server, so one install edits and debugs.
  • A desktop app: the live demo in a window of its own, with the computer’s files in place of the browser’s storage.
a checked box Check it: test and measure
  • xetal test and xetalunit: unit tests in the manner of JUnit, as sw-MLPL’s mlplunit has them. A test is a definition tagged ## @test in a tests/ directory, with @expect error[code], @skip and @tag name; xetal test runs each in its own session and reports as cargo test does, with JUnit XML for CI. The assertions become a standard library, and xetalunit, in X_eTaL-libraries, adds fixtures and parameterized cases.
  • Code coverage: which parts of a program its tests ran.
  • Benchmarking: X_eTaL measures itself already. Its bench/ suite times elementwise arithmetic, reductions and scans, rotations, outer and matrix products, Life and three demos; just bench prints the best of several runs as a table, and a check fails when any of them runs more than 15% slower than the machine’s recorded baseline, so a slowdown can’t slip in unnoticed. X_eTaL-ML guards its demos the same way. What is missing is that for your own programs: a xetal bench that times a function over runs and compares it with a saved baseline.
  • A profiler: where a program spends its time, by function and by expression. The interpreter itself has been profiled with perf, which is how its slow paths were found, but there is no tool for profiling an X_eTaL program yet. The explorer’s run counts, how many times each part ran, are a start.
a steamship Ship it: install and share
  • Installers: today X_eTaL is built from source, with Rust, just and a pinned toolchain. An installer, or a package for Homebrew and the other platforms’ managers, would put xetal on a machine in one step.
  • A package manager: a crates-like system for libraries and their dependencies, so a program can name the libraries it uses, with versions, and have them fetched. Today each repository that uses X_eTaL pins one known-good commit and builds that, and libraries are found beside a program, in userlibs/ or on XETAL_PATH.

Each will get a post here as it grows.

Closing

One motivation for adding comprehensive tools to a new programming language is to ease and encourage adoption. Another is to support AI coding agents, giving them the tools they need to produce high-quality libraries and applications in this language, since they were never trained on it.

Building these tools has been one of the best tests of the language: each one reads every part of it, and building them has turned up things to fix. Future posts in this series will go deeper, one tool at a time.