omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / palindrome-detection.wiki
| 1 | =={{header|Omegese}}== |
| 2 | {{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}} |
| 3 | Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program. |
| 4 | <syntaxhighlight lang="text"> |
| 5 | om2 |
| 6 | text nl "\n" |
| 7 | text tq "\"" |
| 8 | text tex "\" exact " |
| 9 | text tin " inexact " |
| 10 | text tyes "yes" |
| 11 | text tno "no" |
| 12 | text p1 "rotor" |
| 13 | text p2 "level" |
| 14 | text p3 "A man, a plan, a canal: Panama!" |
| 15 | text p4 "In girum imus nocte et consumimur igni" |
| 16 | text p5 "hello" |
| 17 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 18 | fn emit a view uchar * to void |
| 19 | o = ulong 0 |
| 20 | while lt o len a bound 4096 |
| 21 | k = write 1 a o sub len a o |
| 22 | if le k 0 |
| 23 | exit 1 |
| 24 | end |
| 25 | o = add o ulong k |
| 26 | end |
| 27 | end |
| 28 | fn emitb b bool to void |
| 29 | if b |
| 30 | emit tyes |
| 31 | else |
| 32 | emit tno |
| 33 | end |
| 34 | end |
| 35 | note exact compares bytes from both ends |
| 36 | fn exact a view uchar * to bool |
| 37 | n = len a |
| 38 | for i ulong div n 2 |
| 39 | if ne get a i get a sub sub n 1 i |
| 40 | ret false |
| 41 | end |
| 42 | end |
| 43 | ret true |
| 44 | end |
| 45 | note inexact keeps letters only, lower-cased, then compares (strings up to 256 bytes) |
| 46 | fn inexact a view uchar * to bool |
| 47 | b = new uchar 256 0 |
| 48 | n = ulong 0 |
| 49 | for i ulong len a |
| 50 | c = get a i |
| 51 | if and ge c 65 le c 90 |
| 52 | c = add c 32 |
| 53 | end |
| 54 | if and ge c 97 le c 122 |
| 55 | put b n c |
| 56 | n = add n 1 |
| 57 | end |
| 58 | end |
| 59 | ret exact part b 0 n |
| 60 | end |
| 61 | fn show a view uchar * to void |
| 62 | emit tq |
| 63 | emit a |
| 64 | emit tex |
| 65 | emitb exact a |
| 66 | emit tin |
| 67 | emitb inexact a |
| 68 | emit nl |
| 69 | end |
| 70 | fn main to int |
| 71 | show p1 |
| 72 | show p2 |
| 73 | show p3 |
| 74 | show p4 |
| 75 | show p5 |
| 76 | ret 0 |
| 77 | end |
| 78 | </syntaxhighlight> |
| 79 | {{out}} |
| 80 | <pre> |
| 81 | "rotor" exact yes inexact yes |
| 82 | "level" exact yes inexact yes |
| 83 | "A man, a plan, a canal: Panama!" exact no inexact yes |
| 84 | "In girum imus nocte et consumimur igni" exact no inexact yes |
| 85 | "hello" exact no inexact no |
| 86 | </pre> |