0x0LearnReferenceLibraries0x0.jmp0x1b.com

Examples

The examples/ directory contains executable source examples. Prefer examples

that name their expected observable output and can be run with ./bin/zero run.

Minimal Examples

Run:


./bin/zero run examples/add.0x0

Expected output:


42

Other minimal examples:

Realistic Examples

Multi-file import:


./bin/zero run examples/import-main.0x0

Expected output:


42

Namespaced import:


./bin/zero run examples/import-namespaced-main.0x0

Expected output:


42

Package import:


./bin/zero run examples/compiler2-package-import.0x0

Expected output:


true

Edge-Case Examples

ADT and match:


./bin/zero run examples/adt-result.0x0

Expected output:


80

List operations:


./bin/zero run examples/list-ops.0x0

Expected output:


42

Text operations:


./bin/zero run examples/string-ops.0x0

Expected output:


42

Unicode string literal handling:


./bin/zero run examples/unicode-string.0x0

Expected output:


ƒ

Failure Examples

Type mismatch through an imported function:


./bin/zero run examples/compiler2-import-type.0x0

Expected result: non-zero exit status and:


0x0 seed error: imported-add: argument type mismatch

Missing package import:


./bin/zero run examples/compiler2-package-missing.0x0

Expected result: non-zero exit status and:


0x0 seed error: package dependency not found: no-such-dependency

Use failure examples to document stable failure classes, not to claim a

successful runtime behavior.

Adding Examples

Create a scaffold:


sh tools/new-example.sh my-example 42

Then:

1. Keep the example focused on one behavior.

2. Add an expected output comment at the top.

3. Run the example with ./bin/zero run.

4. Update beginner docs and exact reference docs when the example documents new

user-visible behavior.

5. Run make docs-check for documentation updates and the relevant compiler or

runtime gate for behavior updates.