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
omega-mv / si / rosetta / tasks / soundex / soundex.om
| 1 | note Rosetta Code task "Soundex": https://rosettacode.org/wiki/Soundex |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | om2 |
| 4 | text nl "\n" |
| 5 | text sp " " |
| 6 | note code of each letter a..z: 0 vowel (and y), 1..6 consonant groups, 7 h and w (ignored) |
| 7 | text codes "01230127022455012623017202" |
| 8 | text n0 "Robert" |
| 9 | text n1 "Rupert" |
| 10 | text n2 "Rubin" |
| 11 | text n3 "Ashcraft" |
| 12 | text n4 "Ashcroft" |
| 13 | text n5 "Tymczak" |
| 14 | text n6 "Pfister" |
| 15 | text n7 "Honeyman" |
| 16 | text n8 "Lee" |
| 17 | text n9 "Gutierrez" |
| 18 | text n10 "Jackson" |
| 19 | text n11 "VanDeusen" |
| 20 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 21 | fn emit a view uchar * to void |
| 22 | o = ulong 0 |
| 23 | while lt o len a bound 4096 |
| 24 | k = write 1 a o sub len a o |
| 25 | if le k 0 |
| 26 | exit 1 |
| 27 | end |
| 28 | o = add o ulong k |
| 29 | end |
| 30 | end |
| 31 | note American Soundex: keep the first letter, code the rest, drop repeats of the same code (h and w |
| 32 | note do not separate them, vowels do), pad with zeros to four characters |
| 33 | fn soundex a view uchar * to void |
| 34 | o = new uchar 4 48 |
| 35 | c = get a 0 |
| 36 | if ge c 97 |
| 37 | c = sub c 32 |
| 38 | end |
| 39 | put o 0 c |
| 40 | prev = get codes sub c 65 |
| 41 | k = ulong 1 |
| 42 | for i ulong sub len a 1 |
| 43 | x = get a add i 1 |
| 44 | if ge x 97 |
| 45 | x = sub x 32 |
| 46 | end |
| 47 | d = get codes sub x 65 |
| 48 | if eq d 48 |
| 49 | prev = d |
| 50 | else |
| 51 | if and ne d 55 ne d prev |
| 52 | if lt k 4 |
| 53 | put o k d |
| 54 | k = add k 1 |
| 55 | end |
| 56 | prev = d |
| 57 | end |
| 58 | end |
| 59 | end |
| 60 | emit a |
| 61 | emit sp |
| 62 | emit o |
| 63 | emit nl |
| 64 | end |
| 65 | fn main to int |
| 66 | soundex n0 |
| 67 | soundex n1 |
| 68 | soundex n2 |
| 69 | soundex n3 |
| 70 | soundex n4 |
| 71 | soundex n5 |
| 72 | soundex n6 |
| 73 | soundex n7 |
| 74 | soundex n8 |
| 75 | soundex n9 |
| 76 | soundex n10 |
| 77 | soundex n11 |
| 78 | ret 0 |
| 79 | end |