Om by Example
Short, complete programs, one topic per page. Each page shows the source and the exact output it prints. Every program here was compiled and run with the current Om compiler, so what you see is what you get.
Read them in order if you're new, or jump to a topic. Each program also sits in
this folder as an .om file, so you can run it with om run 01-hello.om.
| # | Topic | What it shows |
|---|---|---|
| 1 | Hello, world | The smallest Om program. |
| 2 | Variables and constants | Bindings are immutable unless you write let mut. |
| 3 | Primitive types | Every integer type from i8 to u64, isize/usize, f32, f64, bool and char, with Rust's limits, number methods and as casts. |
| 4 | Functions | Typed parameters, implicit return of the last expression, early return, and Om's default and named arguments. |
| 5 | Control flow | if is an expression. |
| 6 | Structs and methods | Named fields, struct literals with field shorthand, and impl blocks with &self, &mut self and associated functions. |
| 7 | Enums and match | Enums carry data. |
| 8 | Option, Result and ? | No null and no exceptions. |
| 9 | Vec | A growable list that owns its elements. |
| 10 | String and str | String owns text and str is a view of it. |
| 11 | Ownership and borrowing | Moves, .clone(), & and &mut parameters. |
| 12 | Drop | Cleanup runs when a value goes out of scope, in Rust's order. |
| 13 | Box and recursive types | Box[T] stores one value on the heap, which is how a type can contain itself. |
| 14 | Generics | Generic functions, structs and impl blocks. |
| 15 | Traits and operator overloading | Traits with default methods, trait bounds, and + / == through Add and Eq. |
| 16 | Pipeline operator | An Om extra: `x |
| 17 | defer | An Om extra from Zig, Go and Swift: put cleanup right next to setup. |
| 18 | Panics and assert | panic, assert and unwrap print to stderr and exit with code 101. |
Want the longer explanations? Read the Om Book. Back to Learn Om.