clad-lang
v0.7.0
Published
Clad — a token-minimal programming language designed for LLM code generation. Independent project, not affiliated with Anthropic.
Downloads
138
Maintainers
Readme
Clad
A token-minimal programming language designed for LLM code generation (Claude-first, works with any model).
Clad is an independent community project, not affiliated with or endorsed by Anthropic.
Why
- Fewer tokens. No commas, no semicolons, no braces — every construct picked for minimal tokenizer cost while staying close to patterns models already know.
- One canonical form. Exactly one way to write and format each construct; diffs are always semantic.
- Contracts built in.
expect/ensureruntime guards as part of the language. - Errors built for self-repair. Stable error codes with
expected / got / fixfields so a model can fix its code in one iteration.
Quick start
git clone https://github.com/cladlang/clad && cd clad
node src/cli.js run examples/fib.clad
node src/cli.js fmt --check examples/fib.cladOr npm install && npm link to get the clad command. Requires Node ≥ 20. Run the test suite with npm test.
Taste
fn fib(n:int) -> int
expect n >= 0
if n < 2: ret n
ret fib(n - 1) + fib(n - 2)
range(10) |> filter(x -> x % 2 == 0) |> map(x -> x * x) |> sum() |> say()Full language reference: SPEC.en.md (English) / SPEC.md (Russian). Error code reference: docs/errors.md. Examples: examples/.
Status
v0.7 — release candidate: regression test suite (npm test), CI, recursion limits and call-chain tracebacks in errors, packaged CLI. Working tree-walking interpreter and canonical formatter (clad fmt, with --check; comment-preserving, idempotent). Python-habit operators (**, //, +=, ternary a if c else b, elif, break/continue, negative indexing, deep ==, + on lists), iterable strings, and a dense stdlib covering Python's (freq, group, scan, runs, chunks, zip, maxby, uniq, flat, says, title, …).
Benchmarks vs Python over 35 tasks, now including data-processing-heavy ones (bench/results/):
- Tokens: 1557 vs 1834 (−15.1%) on the real Claude tokenizer; Clad cheaper or equal on 31/35 tasks.
- Iterations to green (since v0.6 a Clad solution must also pass
clad fmt --check): v0.4 run — 25/25 first-attempt on both claude-opus-4-8 and claude-fable-5; v0.6 run (35 tasks, fmt enforced) — 35/35 passed, 40 vs 35 attempts, first-attempt output correct on 34/35, and every extra attempt (mostly formatter canonicalization) self-repaired in exactly one round.
Next: static checks for contracts, more data-processing tasks.
