Examples
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: Intentionally invalid: the literal does not fit in i32, and the i64 type does not exist yet.calls.mul: Parameters and calls (RFC-002): main calls sub before its definition.conditions.mul: 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: 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: 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: Variables and blocks (RFC-005): let is immutable, var can be assigned, a block opens a scope. MUL has no shadowing.loops.mul: 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: MVP-0: the smallest program that goes through the whole MUL pipeline.overflow.mul: Well-typed, but overflows i32 at run time.abundant.mul: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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.