omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / 99-bottles-of-beer.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 nomore "No more" |
| 8 | text b1 " bottle" |
| 9 | text bn " bottles" |
| 10 | text wall " of beer on the wall\n" |
| 11 | text beer " of beer\n" |
| 12 | text take "Take one down, pass it around\n" |
| 13 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 14 | fn emit a view uchar * to void |
| 15 | o = ulong 0 |
| 16 | while lt o len a bound 4096 |
| 17 | k = write 1 a o sub len a o |
| 18 | if le k 0 |
| 19 | exit 1 |
| 20 | end |
| 21 | o = add o ulong k |
| 22 | end |
| 23 | end |
| 24 | note emitu writes n in decimal; 20 digits hold every ulong |
| 25 | fn emitu n ulong to void |
| 26 | d = new uchar 20 0 |
| 27 | i = ulong 20 |
| 28 | v = n |
| 29 | while true bound 20 |
| 30 | i = sub i 1 |
| 31 | put d i uchar add rem v 10 48 |
| 32 | v = div v 10 |
| 33 | if eq v 0 |
| 34 | break |
| 35 | end |
| 36 | end |
| 37 | emit part d i sub 20 i |
| 38 | end |
| 39 | fn bottles n ulong to void |
| 40 | if eq n 0 |
| 41 | emit nomore |
| 42 | else |
| 43 | emitu n |
| 44 | end |
| 45 | if eq n 1 |
| 46 | emit b1 |
| 47 | else |
| 48 | emit bn |
| 49 | end |
| 50 | end |
| 51 | fn main to int |
| 52 | for i ulong 99 |
| 53 | n = sub 99 i |
| 54 | bottles n |
| 55 | emit wall |
| 56 | bottles n |
| 57 | emit beer |
| 58 | emit take |
| 59 | bottles sub n 1 |
| 60 | emit wall |
| 61 | if lt i 98 |
| 62 | emit nl |
| 63 | end |
| 64 | end |
| 65 | ret 0 |
| 66 | end |
| 67 | </syntaxhighlight> |
| 68 | {{out}} |
| 69 | <pre> |
| 70 | 99 bottles of beer on the wall |
| 71 | 99 bottles of beer |
| 72 | Take one down, pass it around |
| 73 | 98 bottles of beer on the wall |
| 74 | |
| 75 | 98 bottles of beer on the wall |
| 76 | 98 bottles of beer |
| 77 | Take one down, pass it around |
| 78 | 97 bottles of beer on the wall |
| 79 | |
| 80 | 97 bottles of beer on the wall |
| 81 | 97 bottles of beer |
| 82 | Take one down, pass it around |
| 83 | 96 bottles of beer on the wall |
| 84 | |
| 85 | ... |
| 86 | 2 bottles of beer |
| 87 | Take one down, pass it around |
| 88 | 1 bottle of beer on the wall |
| 89 | |
| 90 | 1 bottle of beer on the wall |
| 91 | 1 bottle of beer |
| 92 | Take one down, pass it around |
| 93 | No more bottles of beer on the wall |
| 94 | </pre> |