interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / phrase-reversals.wiki

81 lines · 1563 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text sp " "
8text msg "rosetta code phrase reversal"
9note emit writes every byte of a to stdout; a short write is retried, an error exits 1
10fn emit a view uchar * to void
11o = ulong 0
12while lt o len a bound 4096
13k = write 1 a o sub len a o
14if le k 0
15exit 1
16end
17o = add o ulong k
18end
19end
20note emitc writes one byte
21fn emitc c uchar to void
22b = new uchar 1 0
23put b 0 c
24emit b
25end
26note words splits a into (start, length) pairs at single spaces and returns how many
27fn words a view uchar * st edit ulong 16 ln edit ulong 16 to ulong
28k = ulong 0
29s = ulong 0
30for i ulong add len a 1
31e = eq i len a
32if not e
33e = eq get a i 32
34end
35if e
36put st k s
37put ln k sub i s
38k = add k 1
39s = add i 1
40end
41end
42ret k
43end
44fn revb a view uchar * to void
45for i ulong len a
46emitc get a sub sub len a 1 i
47end
48end
49fn main to int
50st = new ulong 16 0
51ln = new ulong 16 0
52k = words msg st ln
53note 1: the whole string reversed
54revb msg
55emit nl
56note 2: each word reversed, order kept
57for w ulong k
58if gt w 0
59emit sp
60end
61revb part msg get st w get ln w
62end
63emit nl
64note 3: the word order reversed, words kept
65for w ulong k
66if gt w 0
67emit sp
68end
69x = sub sub k 1 w
70emit part msg get st x get ln x
71end
72emit nl
73ret 0
74end
75</syntaxhighlight>
76{{out}}
77<pre>
78lasrever esarhp edoc attesor
79attesor edoc esarhp lasrever
80reversal phrase code rosetta
81</pre>