Om Exercises
Twelve small programs that don't work yet. Your job is to fix each one so that
om run prints ok. They follow the order of the Om Book,
so read a chapter, then do its exercises.
$ om run 01_variables.om
error: cannot assign twice to `count`; declare it with `let mut count`
...
(fix the file)
$ om run 01_variables.om
okSome exercises don't compile until you fix them; others compile and then fail
an assert. Either way, read the message: it usually tells you what to do.
| # | Exercise | Book chapter | Hint |
|---|---|---|---|
| 1 | 01_variables.om |
3 | Variables can't change unless you say so. |
| 2 | 02_functions.om |
3 | Parameters need types, and so does the return value. |
| 3 | 03_if.om |
3 | if produces a value; both branches must too. |
| 4 | 04_loops.om |
3 | 1..=n includes n. |
| 5 | 05_move.om |
4 | A function that only reads a list should borrow it. |
| 6 | 06_borrow_mut.om |
4 | Changing the caller's value needs &mut in two places. |
| 7 | 07_structs.om |
5 | One method reads self, the other changes it. |
| 8 | 08_match.om |
6 | The error names the missing case. |
| 9 | 09_option.om |
7 | Return Some(...) as soon as you find it. |
| 10 | 10_result.om |
7 | One character per line. |
| 11 | 11_strings.om |
8 | chars() returns a Vec[char]; take element [0]. |
| 12 | 12_traits.om |
9 | Two impl blocks and one function with a bound. |
Stuck? Every exercise has a worked answer in solutions/. Try
for a while before you look.
Planned: an om exercises runner that checks your progress and moves to the
next exercise automatically, like Rust's Rustlings.
Back to Learn Om.