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 / reverse-words-in-a-string.wiki

75 lines · 1626 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 poem "---------- Ice and Fire ------------\n\nfire, in end will world the say Some\nice. in say Some\ndesire of tasted I've what From\nfire. favor who those with hold I\n\n... elided paragraph last ...\n\nFrost Robert -----------------------\n"
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 revline prints the space-separated words of a in reverse order, one space between them
21fn revline a view uchar * to void
22st = new ulong 64 0
23ln = new ulong 64 0
24k = ulong 0
25i = ulong 0
26while lt i len a bound 4096
27if eq get a i 32
28i = add i 1
29else
30j = i
31while lt j len a bound 4096
32if eq get a j 32
33break
34end
35j = add j 1
36end
37put st k i
38put ln k sub j i
39k = add k 1
40i = j
41end
42end
43for w ulong k
44if gt w 0
45emit sp
46end
47x = sub sub k 1 w
48emit part a get st x get ln x
49end
50emit nl
51end
52fn main to int
53s = ulong 0
54for i ulong len poem
55if eq get poem i 10
56revline part poem s sub i s
57s = add i 1
58end
59end
60ret 0
61end
62</syntaxhighlight>
63{{out}}
64<pre>
65------------ Fire and Ice ----------
66
67Some say the world will end in fire,
68Some say in ice.
69From what I've tasted of desire
70I hold with those who favor fire.
71
72... last paragraph elided ...
73
74----------------------- Robert Frost
75</pre>