Landin library reference source

compiler/tests/fixtures/runtime/library-shared-text/main.ldn

1import core/text
2
3exercise: () -> (ok: bool) ! text.past_end =
4    ok = false
5    source: [1]u8 = [42]
6    first := text.first(source[0..<1])
7    found := try text.byte(source[0..<1], first)
8    return when found <> 42
9    _ = text.byte(source[0..<1], text.next(first)) else (problem)
10        ok = problem == text.past_end
11        return
12    end
13end exercise
14
15public main: () -> (code: i32) =
16    code = 1
17    ok := exercise() else false
18    if ok then
19        code = 42
20    end if
21end main