interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / loops-foreach / loops-foreach.om

28 lines · 710 bytes Raw Blame History
1note Rosetta Code task "Loops/Foreach": https://rosettacode.org/wiki/Loops/Foreach
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5note the collection: names separated by newlines
6text fruit "apple\nbanana\ncherry\ndate\nelderberry\n"
7note emit writes every byte of a to stdout; a short write is retried, an error exits 1
8fn emit a view uchar * to void
9o = ulong 0
10while lt o len a bound 4096
11k = write 1 a o sub len a o
12if le k 0
13exit 1
14end
15o = add o ulong k
16end
17end
18note foreach visits every newline-terminated element of the collection in order
19fn main to int
20s = ulong 0
21for i ulong len fruit
22if eq get fruit i 10
23emit part fruit s add sub i s 1
24s = add i 1
25end
26end
27ret 0
28end