# Examples

Each page below is generated when the site is built: the source comes from
`examples/`, and the IR and the run output are what the `mul` CLI printed for
it in that build. The comparison programs show the evidence committed in
`examples/compare/evidence/`, which the build first checks against the programs.

- [`broken.mul`](/examples/broken/): Intentionally invalid: the literal does not fit in i32, and the i64 type does not exist yet.
- [`calls.mul`](/examples/calls/): Parameters and calls (RFC-002): main calls sub before its definition.
- [`conditions.mul`](/examples/conditions/): Collatz sequence: how many steps it takes n to reach 1. next is assigned on one path only; the IR merges it with a block parameter.
- [`effects.mul`](/examples/effects/): Effects: pure (the default) and io (RFC-009). A pure function cannot call an io one; mul check rejects that with MUL-T013.
- [`hello.mul`](/examples/hello/): Hello, world (RFC-010): print is an io operation, so main is io. mul run prints the line and exits with the value of main, here 0.
- [`locals.mul`](/examples/locals/): Variables and blocks (RFC-005): let is immutable, var can be assigned, a block opens a scope. MUL has no shadowing.
- [`loops.mul`](/examples/loops/): Greatest common divisor by Euclid's algorithm: a and b change on every iteration, so the loop header takes both as block parameters.
- [`mvp0.mul`](/examples/mvp0/): MVP-0: the smallest program that goes through the whole MUL pipeline.
- [`overflow.mul`](/examples/overflow/): Well-typed, but overflows i32 at run time.
- [`abundant.mul`](/examples/compare-abundant/): The abundant program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`collatz.mul`](/examples/compare-collatz/): The collatz program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`digits.mul`](/examples/compare-digits/): The digits program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`fib.mul`](/examples/compare-fib/): The fib program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`fizzbuzz.mul`](/examples/compare-fizzbuzz/): The fizzbuzz program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`gcd.mul`](/examples/compare-gcd/): The gcd program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`hello.mul`](/examples/compare-hello/): The hello program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`isqrt.mul`](/examples/compare-isqrt/): The isqrt program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`power.mul`](/examples/compare-power/): The power program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
- [`primes.mul`](/examples/compare-primes/): The primes program written in MUL, Go, PHP, C and Rust, with the same output and exit code, and the token count of each version.
