A block print of a wooden see-saw on a playground, a handle at each end of its plank, on a post set in a worn dirt path among grass and wildflowers, with a fence and bare trees behind

This week’s saw is X_eTaL itself. Writing about how to read X_eTaL, for episode 7 of my array languages videos and Array Languages #27, meant running every example on the page, and several of them did not do what they should. Each became a fix. At the same time, six new repositories started putting the language to work, as building blocks for future experiments, demos, videos and posts.

Resource Link
Language X_eTaL, playground
Found while writing Array Languages #27, episode 7
Flow X_eTaL-FBP, X_eTaL-microservices, and the books behind them: Worth Reading #4
Structures X_eTaL-data-structures, live
Algorithms X_eTaL-algorithms, live
Tensors X_eTaL-tensors
Graphics X_eTaL-graphics
The series Sharpen the Saw: every post
“Sharpen the Saw” The 7 Habits of Highly Effective People (Stephen Covey)
Comments Discord

A flurry of fixes

An example in a blog post or a video is a test with an audience. Each line is drawn by X_eTaL and run before it is shown, so when one gives an error it should not, or an error gives bad advice, the language gets fixed rather than the example quietly dropped. This week that happened again and again:

What went wrong Now Fix
A code string with broken code, as x ← c"1 + (2", was accepted unless a macro read it every code string is parsed before any macro runs, and the error points inside the string a08bda1c
x⁰·⁵ with an Int x was a type error a decimal or negative superscript makes the base a Float first: with x ← 4, 2.0 bf2acc0f, 0854fb71
A library’s variable, ˡacc! ← 0, lost its !, and the library’s own functions could not change it the library’s functions change it; a program reads it as ᵃacc!, and writing it is refused (error[imported-name]) 03d16ee4
Inside a function, ʰy! ← x with no such top-level name made a new local a prefixed name never becomes a local: error[bad-binding], naming the top level b36bfdc6
A function name could carry its underline on any letter, ᵘab̲c, easy to misread as another name the underline goes on the first letter; lint warns underline-not-first now, and it will become an error 2dd88be0
The error for '+^4 suggested a fix that does not type-check it explains that a power repeats a one-argument function, and shows a lambda repeated with p̲ower 0e26b435
The several-axes error left out transpose, which takes two, as s̲hape o̲\₂₃ B it lists rotate, transpose, reduce and scan 84c3c033
f̲irst of an empty array told you to join a fill first, which cannot help it says the array is empty and has no first item to retrieve 05c31743

One more turned up while I reviewed the finished video. The same visible word, t̲ally "café", counted 4 or 5 depending on how the accent was typed: as one character, é, or as an e followed by a combining accent. Both counts are right by the rules, since a string is an array of Unicode code points and t̲ally counts items, but neither tells you what a reader sees. Rather than change what a character is, X_eTaL gained g̲lyphs (b624b06d). It splits a text into the characters a person sees (Unicode’s grapheme clusters), one box each, so every array function works by glyph and e̲nlist joins them back:

t̲ally "café"                                      ⍝ 4: é typed as one character
t̲ally "café"                                      ⍝ 5: e, then a combining accent
t̲ally g̲lyphs "café"                               ⍝ 4
t̲ally g̲lyphs "café"                               ⍝ 4
e̲nlist r̲ev g̲lyphs "café"                          ⍝ éfac

A reversed glyph keeps its accent on its letter; plain r̲ev on the second spelling leaves the accent with nothing to sit on. A thumbs-up with a skin tone, a family joined into one emoji, or a flag is one glyph too. The two spellings still differ, so m̲atch says 0; normalizing text literals, so that both spellings become the same, is planned next.

Some findings were decisions rather than bugs. The spaced power, x ^ 0.5, still refuses an Int and a Float: only the superscript converts, because its exponent is written in the source, and ordinary arithmetic never mixes number types silently. And one led to a design change, planned but not yet made: a plain name bound inside a function will be the function’s own local, and a function changes a global only through a prefixed name (bd6064c5).

Also new in X_eTaL

  • A debugger that steps backward. xetal debug FILE opens the program in the terminal with the stack, variables, watches and breakpoints beside it; it steps over, in and out, and also back, or runs in reverse (259e7b73). It can step through a macro’s expanded code as a source of its own (f4f8b6f4), and the same session runs on a page of the live demo (bb7d8265).
  • An array viewer. A large array shown as a grid that pages and pans, a rank-3 array as slices side by side or a block of cubes, colored by magnitude on request, as text or SVG, in the debugger and in VS Code (5a16e1d5).
  • Writing a library in the browser. The live demo’s Library view puts a library beside a program that uses it, both typed and drawn, with the program’s types below (f3f66c54).
  • Two primitives from APL2. 1 2 3 2 4 w̲ithout 2 4 gives 1 3; enlist flattens a nested array (8ded54e0).
  • Ranges stay ranges. r̲ange is kept as a start, a step and a count instead of every item, so '+ r̲/ r̲ange 1000000 is computed in closed form (94d1be68).
  • Check or assert. c̲heck< reports a failed condition and goes on; a̲ssert< now stops, as Rust’s assert! does (e5db8353).

Planned next: the live demo as a desktop application, with Open and Save on the disk.

Six new building blocks

Each new repository asks one question of the language, and each answer is a set of libraries other X_eTaL programs can import. All six started this week:

Repository The question So far
X_eTaL-FBP can X_eTaL express classical flow-based programming? connections, packets, networks and a scheduler: a network runs
X_eTaL-microservices can a whole distributed system be executable, analyzable data? the plan, a pattern coverage matrix, topologies, load balancing
X_eTaL-data-structures what does a data structure become with no pointers and no mutation? stacks, queues, deques, rings, a heap, and a live demo
X_eTaL-algorithms the textbook way, the functional way, the array way: when does each win? processes and prefix sums, and a live explorer
X_eTaL-tensors can tensors be built with no new type at all? tensors, shapes, layouts, contractions and einsum
X_eTaL-graphics can X_eTaL drive a modern GPU without graphics in the language? a renderer on wgpu: a triangle and a lit, turning cube

They also test each other: the algorithms repository depends on the data structures through a written contract, and the microservices build on the flow-based programming.

Flow-based programming

A block print titled PIPES: pipes with elbows, couplings and a valve, crossing and joining, with arrows showing the flow. A block print titled PIPES: pipes with elbows, couplings and a valve, crossing and joining, with arrows showing the flow.

X_eTaL-FBP is classical flow-based programming as J. Paul Morrison designed it, and described it in Flow-Based Programming (1994), written in X_eTaL. An application is a network of independently running processes that pass information packets through bounded connections between named ports. The network is defined apart from its components, so a component never names its neighbors, and a full connection holds its producer back. Four libraries are done: bounded connections with four overflow policies (block, drop the oldest, drop the newest, reject); packets with an identity and an owner checked on every move; networks as data, validated and analyzed for loops, sources and sinks; and a scheduler that runs a network tick by tick, every packet accounted for and every event traced. It is deterministic, so every run is repeatable and a run is a test.

Microservices

A block print titled MICROSERVICES: small boxes, each marked with gears, lists or charts, joined by dashed arrows in both directions. A block print titled MICROSERVICES: small boxes, each marked with gears, lists or charts, joined by dashed arrows in both directions.

X_eTaL-microservices builds the service level on top, following the patterns Chris Richardson catalogs in Microservices Patterns (2018): contracts, topologies, routing and load balancing, progressive deployment (A/B, canary, shadow, rollback), resilience, sagas, event sourcing and tracing, written as X_eTaL specifications and run first as simulations. The policies are pure X_eTaL functions over arrays, where a transaction goes, when a version is rolled back, when a breaker opens; the mechanisms, networking and processes, will come from Rust. So far: service topologies as data, and instance selection by six load-balancing algorithms.

Both books shaped these two repositories. I wrote about them, and how they have influenced my approach to platform development, in Worth Reading #4.

Data structures

A block print titled DATA STRUCTURES: two trees, arrays of cells, and lists linked by arrows. A block print titled DATA STRUCTURES: two trees, arrays of cells, and lists linked by arrows.

X_eTaL-data-structures asks what the classic structures become in a language with immutable values and no pointers. Every structure is persistent, since an operation returns a new one and undo is keeping the old value. Links are indices: a linked list is a vector of values and a vector of next positions. And many structures turn into whole-array expressions: a set is a membership mask, a graph a matrix. Stacks, queues, deques, rings and a heap are done, each library saying what carries over unchanged, what changes shape, and what does not fit yet. Its live demo runs every library’s examples in the browser.

Algorithms

A block print titled ALGORITHMS: a flowchart of decisions and loops, beside plotted curves and a sorted table. A block print titled ALGORITHMS: a flowchart of decisions and loops, beside plotted curves and a sorted table.

X_eTaL-algorithms writes each classic algorithm three ways side by side: the textbook loop, recursion over immutable values, and the whole array at once. Each is checked against its laws (a sort’s output is ordered, and a permutation of its input) and against the other two, and a traced variant returns every state it passed through and what it counted, so a run can be replayed and drawn. So far: factorial and Fibonacci as computational processes, and the running total, with a live explorer.

Tensors

A block print titled TENSORS: a matrix of numbers and cubes of numbered cells, with arrows along their axes. A block print titled TENSORS: a matrix of numbers and cubes of numbered cells, with arrows along their axes.

X_eTaL-tensors builds tensors from what X_eTaL already has. A tensor is an array, so a number is a rank-0 tensor and a batch of color images rank 4; the type says Int or Float, and the shape is data, checked when the program runs. A single number extends over an array, but two arrays of different shapes are an error, never silently broadcast: broadcasting is asked for by name. The libraries so far cover tensor creation and checks, shapes and explicit broadcasting, flat and strided views without copying, contractions and products, and einsum, whose spec is checked when the program is compiled. Neural layers, convolution and quantization are next, and later a tensor inspector, a live site, and Rust-backed and GPU execution.

Graphics

A block print titled GRAPHICS: wireframe polyhedra and triangles turning into a mesh, and pixels stepping across it. A block print titled GRAPHICS: wireframe polyhedra and triangles turning into a mesh, and pixels stepping across it.

X_eTaL-graphics is a small Rust renderer on wgpu, with WGSL shaders, so one code base draws on Metal, Vulkan, Direct3D 12 or WebGPU. The idea is that X_eTaL computes the scene and Rust and the GPU draw it. An army of ten thousand soldiers is a few arrays (positions, angles, meshes) computed by X_eTaL and handed to the renderer, which draws each mesh once, instanced; the game stays in X_eTaL. Programs will reach the renderer through X_eTaL’s native extensions, as typed operations over arrays, so the language itself gains no graphics types or syntax.

The X_eTaL-graphics triangle demo on Metal: a triangle shading from red at the top to green and blue at the base, on a dark background
The triangle demo on Metal, captured from its window. Click to enlarge.

So far it probes each GPU and classifies it into a capability profile, renders offscreen against golden images, and draws a triangle and a lit, turning cube in a window, reporting frame rate, frame-time percentiles, draws per frame and bytes uploaded per frame. This may be how I make future games with much better graphics and higher frame rates.

Closing

Covey’s seventh habit is taking time to sharpen the saw instead of only sawing. This week the saw was the language itself: every example I wanted to show became a test, and every failure became a fix. Each of the six new repositories is a building block I can reach for in a future experiment, demo, video or post: a flow network, a persistent structure, an einsum, a GPU that draws what X_eTaL computes. The graphics one is the one I’m most curious about, since it may let me make future games with much better graphics and higher frame rates.