interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / comma-quibbling / comma-quibbling.om

65 lines · 1162 bytes Raw Blame History
1note Rosetta Code task "Comma quibbling": https://rosettacode.org/wiki/Comma_quibbling
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text lb "{"
6text rb "}"
7text sep ", "
8text tand " and "
9text w1 "ABC"
10text w2 "ABC DEF"
11text w3 "ABC DEF G H"
12note emit writes every byte of a to stdout; a short write is retried, an error exits 1
13fn emit a view uchar * to void
14o = ulong 0
15while lt o len a bound 4096
16k = write 1 a o sub len a o
17if le k 0
18exit 1
19end
20o = add o ulong k
21end
22end
23note quib takes the words of a (single spaces between them): all but the last two are followed by a
24note comma, the last two are joined by "and", inside braces
25fn quib a view uchar * to void
26st = new ulong 16 0
27ln = new ulong 16 0
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 and e gt i s
36put st k s
37put ln k sub i s
38k = add k 1
39end
40if e
41s = add i 1
42end
43end
44emit lb
45for w ulong k
46if gt w 0
47if eq w sub k 1
48emit tand
49else
50emit sep
51end
52end
53emit part a get st w get ln w
54end
55emit rb
56emit nl
57end
58fn main to int
59note the empty list, as a slice of length 0
60quib part w1 0 0
61quib w1
62quib w2
63quib w3
64ret 0
65end