AgentSlangASL
← All posts

Written for the Model, Checked for the Human: Why ASL Uses S-Expressions and Closed Variants

These notes were written in September 2026, before the C host was removed, and describe designs as well as shipped behaviour. Where a post says asl-host check or asl-host test, the command today is asl check or asl test; ERR_READ_UNBALANCED is now ERR_UNBALANCED; and the current checker does not reject an unmarked effect (ERR_EFFECT_UNMARKED). Figures are the ones measured on the date each post gives. Current docs

By GenSEAM | September 2026

AgentSlang (ASL) is built so that a model writes it and a checker vouches for it. Three choices carry that: single-pass S-expressions, closed algebraic variants with exhaustive matching, and explicit effect markers. The model gets a syntax with nothing to guess at; the reviewer gets a checker verdict instead of a wall of code. And because ASL code, ASN data and toolbelt calls share one syntax, the same habits cover all three.

The languages most agents write today were designed between 1970 and 2015 around a different premise: syntax should optimize for human visual cognition.

Infix operators (a + b * c), indentation-based block hierarchies, implicit type coercion, ternary conditionals, and semicolon delimiters were all chosen to reduce human typing strain and follow natural reading habits.

Large language models do not have eyes, biological working memory, or keyboards. They are autoregressive decoders: each subword token is predicted from the tokens before it, and nothing after it.

When an LLM generates Python, JavaScript, or C++, part of its work goes into resolving lexical ambiguities, tracking invisible indentation, and applying operator precedence.

ASL is designed for model authors first. This post argues why its combination suits LLM generation and verification, and marks which parts the checker enforces today.


1. Homoiconicity and Causal Conditioning: Code as a Tree

In conventional compilers, source code goes through several stages: lexing into tokens, parsing into a concrete syntax tree with precedence rules (for example the shunting-yard algorithm), and lowering into an abstract syntax tree.

In AgentSlang, the written form is already the tree. This property is known as homoiconicity.

(module core/fsm :x [step runTests] :i [])

enum State (idle) (active sessionId: String) (errored code: Int64)

enum Event (start sessionId: String) (finish) (fail code: Int64)

fn step current: State ev: Event -> State
  (match current
    ((idle)
     (match ev
       ((start s) (active s))
       ((finish) (idle))
       ((fail c) (errored c))))
    ((active s)
     (match ev
       ((start _) (errored 101))
       ((finish) (idle))
       ((fail c) (errored c))))
    ((errored c) (errored c)))

fn runTests -> Bool
  (do
    (assert (= (step (idle) (start "s1")) (active "s1")) "idle starts a session")
    (assert (= (step (active "s1") (start "s2")) (errored 101)) "double start errors")
    true)

This module passes asl check, and asl test executes both assertions.

The Causal Conditioning Advantage

In infix languages, an operator appears between its operands: operand_A + operand_B. An autoregressive model generates operand_A before it has output the operator that says what operand_A is for.

In prefix S-expressions, the form head always precedes its arguments: (f a1 a2 ... ak).

When the model emits the head f (for example match, +, filter, or a user function), that head is already in the causal context for every argument token a1 to ak. Generation of the operands is conditioned on the operation being performed. That is the hypothesis; Section 5 says how we intend to measure its effect.


2. Balanced Parentheses by Construction: No Precedence to Resolve

Consider the following JavaScript expression:

const result = a + b * c > d ? e : f;

To read this single line correctly, a model has to apply five precedence levels: multiplication, addition, relational comparison, the ternary conditional, and assignment.

In AgentSlang, operator precedence does not exist:

(let [(result (if (> (+ a (* b c)) d) e f))]
  result)

Evaluation order is given by nesting alone. Every expression opens with ( and closes with ).

Delimiters as Causal Anchors

A frequent failure in generated Python is the "runaway block": a loop or comprehension that does not end where the model meant it to, because ending a block means emitting less indentation rather than a token.

In ASL, closing a form is always the explicit token ), and each bracket kind pairs exactly: ( ) forms, [ ] lists, { } records. The checker rejects a mismatch before running anything (ERR_READ_UNBALANCED ')' closes '[').


3. Closed Variants (enum) and Exhaustive match

In dynamic languages, runtime failures such as AttributeError: 'NoneType' object has no attribute 'val' or TypeError: Cannot read properties of undefined are a common way for an agent's run to go wrong.

AgentSlang removes some of these classes by construction:

  1. Closed variants (enum): Cases carry typed payloads, as in enum State (idle) (active sessionId: String) (errored code: Int64). There is no nil: absence is (none), and builtins such as list-head and map-get return (some v) or (none).
  2. Exhaustive matching (match): asl check verifies that every variant of an enum is covered. Removing the (errored c) arm from the module above makes it fail with ERR_MATCH_NONEXHAUSTIVE match over enum State misses variant(s): errored.

If an agent adds a variant, the checker rejects every downstream match that does not handle it, before any code runs.


4. Explicit Effect Markers

One of the larger reliability hazards of autonomous agents is the unconstrained side effect: an agent asked to calculate a metric calls something that writes to disk, changes the environment, or opens a connection.

ASL makes the difference visible in every function header. A function that names an effectful builtin such as println, or calls another effectful function, must be marked, either as fn ! name ... or with a trailing ! in its name. asl check enforces this before anything runs:

(module demo/effects :x [greet total])

fn ! greet name: String -> Unit
  (println name)

fn total a: Int64 b: Int64 -> Int64
  (do (greet "x") (+ a b))
ERR_EFFECT_UNMARKED fn total names effectful greet: mark it (fn ! total ...) or rename it total!

The marker propagates: a pure function cannot hide an effect by calling a marked helper. A lambda carries its own marker, (fn ! [p] ...), so one map serves both kinds.

What the marker does not yet give you is a sandbox. The checker verifies the marking but does not run marked code inside a granted capability context; that is still a design goal. The closest thing today is the wasm32 build of asl-target-llvm, where print is the only host builtin and file, clock, environment and socket calls fail with ERR_CAPABILITY_ABSENT.


5. Measuring the Claim

The argument above predicts that models produce valid ASL more often on the first try than Python, Rust or TypeScript, and need fewer repair turns. The way to test it is to give models the same specifications in each language, check every output with that language's strictest checker, and record first-pass validity, repair turns and scope errors with the models, the task set and the date. We have not run that comparison with a recorded result, so this post quotes no entropy or validity figures.

Try It

The asl CLI is the reference checker. Save the state machine above as fsm.asl and run:

asl check fsm.asl
asl test fsm.asl

The first prints ok; the second reports two assertions executed. If you find a balanced S-expression that the checker reads inconsistently, or a program it accepts that it should reject, open an issue with the file and the checker's output.