interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / reverse-words-in-a-string / reverse-words-in-a-string.om

59 lines · 1289 bytes Raw Blame History
1note Rosetta Code task "Reverse words in a string": https://rosettacode.org/wiki/Reverse_words_in_a_string
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text 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"
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 revline prints the space-separated words of a in reverse order, one space between them
19fn revline a view uchar * to void
20st = new ulong 64 0
21ln = new ulong 64 0
22k = ulong 0
23i = ulong 0
24while lt i len a bound 4096
25if eq get a i 32
26i = add i 1
27else
28j = i
29while lt j len a bound 4096
30if eq get a j 32
31break
32end
33j = add j 1
34end
35put st k i
36put ln k sub j i
37k = add k 1
38i = j
39end
40end
41for w ulong k
42if gt w 0
43emit sp
44end
45x = sub sub k 1 w
46emit part a get st x get ln x
47end
48emit nl
49end
50fn main to int
51s = ulong 0
52for i ulong len poem
53if eq get poem i 10
54revline part poem s sub i s
55s = add i 1
56end
57end
58ret 0
59end