interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / reverse-a-string / reverse-a-string.om

32 lines · 707 bytes Raw Blame History
1note Rosetta Code task "Reverse a string": https://rosettacode.org/wiki/Reverse_a_string
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text s1 "asdf"
6text s2 "Hello, World!"
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 reverses bytes, so it is correct for ASCII only; strings up to 256 bytes (longer traps 3)
19fn rev a view uchar * to void
20r = new uchar 256 0
21n = len a
22for i ulong n
23put r i get a sub sub n 1 i
24end
25emit part r 0 n
26emit nl
27end
28fn main to int
29rev s1
30rev s2
31ret 0
32end