interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / array-concatenation / array-concatenation.om

61 lines · 1115 bytes Raw Blame History
1note Rosetta Code task "Array concatenation": https://rosettacode.org/wiki/Array_concatenation
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6note emit writes every byte of a to stdout; a short write is retried, an error exits 1
7fn emit a view uchar * to void
8o = ulong 0
9while lt o len a bound 4096
10k = write 1 a o sub len a o
11if le k 0
12exit 1
13end
14o = add o ulong k
15end
16end
17note emitu writes n in decimal; 20 digits hold every ulong
18fn emitu n ulong to void
19d = new uchar 20 0
20i = ulong 20
21v = n
22while true bound 20
23i = sub i 1
24put d i uchar add rem v 10 48
25v = div v 10
26if eq v 0
27break
28end
29end
30emit part d i sub 20 i
31end
32note cat copies x then y into r and returns the length
33fn cat x view ulong * y view ulong * r edit ulong * to ulong
34for i ulong len x
35put r i get x i
36end
37for i ulong len y
38put r add len x i get y i
39end
40ret add len x len y
41end
42fn main to int
43a = new ulong 3 0
44b = new ulong 4 0
45c = new ulong 7 0
46for i ulong 3
47put a i add i 1
48end
49for i ulong 4
50put b i add i 4
51end
52n = cat a b c
53for i ulong n
54if gt i 0
55emit sp
56end
57emitu get c i
58end
59emit nl
60ret 0
61end