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 / palindrome-detection / palindrome-detection.om

75 lines · 1333 bytes Raw Blame History
1note Rosetta Code task "Palindrome detection": https://rosettacode.org/wiki/Palindrome_detection
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text tq "\""
6text tex "\" exact "
7text tin " inexact "
8text tyes "yes"
9text tno "no"
10text p1 "rotor"
11text p2 "level"
12text p3 "A man, a plan, a canal: Panama!"
13text p4 "In girum imus nocte et consumimur igni"
14text p5 "hello"
15note emit writes every byte of a to stdout; a short write is retried, an error exits 1
16fn emit a view uchar * to void
17o = ulong 0
18while lt o len a bound 4096
19k = write 1 a o sub len a o
20if le k 0
21exit 1
22end
23o = add o ulong k
24end
25end
26fn emitb b bool to void
27if b
28emit tyes
29else
30emit tno
31end
32end
33note exact compares bytes from both ends
34fn exact a view uchar * to bool
35n = len a
36for i ulong div n 2
37if ne get a i get a sub sub n 1 i
38ret false
39end
40end
41ret true
42end
43note inexact keeps letters only, lower-cased, then compares (strings up to 256 bytes)
44fn inexact a view uchar * to bool
45b = new uchar 256 0
46n = ulong 0
47for i ulong len a
48c = get a i
49if and ge c 65 le c 90
50c = add c 32
51end
52if and ge c 97 le c 122
53put b n c
54n = add n 1
55end
56end
57ret exact part b 0 n
58end
59fn show a view uchar * to void
60emit tq
61emit a
62emit tex
63emitb exact a
64emit tin
65emitb inexact a
66emit nl
67end
68fn main to int
69show p1
70show p2
71show p3
72show p4
73show p5
74ret 0
75end