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 / substring / substring.om

48 lines · 1029 bytes Raw Blame History
1note Rosetta Code task "Substring": https://rosettacode.org/wiki/Substring
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text str "abcdefgh"
6text cd "cd"
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 find returns the first index where t occurs in s; a missing t traps 9
19fn find s view uchar * t view uchar * to ulong
20for i ulong add sub len s len t 1
21m = true
22for j ulong len t
23if ne get s add i j get t j
24m = false
25end
26end
27if m
28ret i
29end
30end
31trap 9
32end
33fn line a view uchar * to void
34emit a
35emit nl
36end
37fn main to int
38n = ulong 2
39m = ulong 3
40note n characters in, m long; from n to the end; all but the last; from d, m long; from cd, m long
41line part str n m
42line part str n sub len str n
43line part str 0 sub len str 1
44c = new uchar 1 100
45line part str find str c m
46line part str find str cd m
47ret 0
48end