Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/phrase-reversals/phrase-reversals.om # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / phrase-reversals / phrase-reversals.om` 72 lines ยท 1348 bytes Raw Blame History 1 note Rosetta Code task "Phrase reversals": https://rosettacode.org/wiki/Phrase_reversals 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text msg "rosetta code phrase reversal" 7 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 8 fn emit a view uchar * to void 9 o = ulong 0 10 while lt o len a bound 4096 11 k = write 1 a o sub len a o 12 if le k 0 13 exit 1 14 end 15 o = add o ulong k 16 end 17 end 18 note emitc writes one byte 19 fn emitc c uchar to void 20 b = new uchar 1 0 21 put b 0 c 22 emit b 23 end 24 note words splits a into (start, length) pairs at single spaces and returns how many 25 fn words a view uchar * st edit ulong 16 ln edit ulong 16 to ulong 26 k = ulong 0 27 s = ulong 0 28 for i ulong add len a 1 29 e = eq i len a 30 if not e 31 e = eq get a i 32 32 end 33 if e 34 put st k s 35 put ln k sub i s 36 k = add k 1 37 s = add i 1 38 end 39 end 40 ret k 41 end 42 fn revb a view uchar * to void 43 for i ulong len a 44 emitc get a sub sub len a 1 i 45 end 46 end 47 fn main to int 48 st = new ulong 16 0 49 ln = new ulong 16 0 50 k = words msg st ln 51 note 1: the whole string reversed 52 revb msg 53 emit nl 54 note 2: each word reversed, order kept 55 for w ulong k 56 if gt w 0 57 emit sp 58 end 59 revb part msg get st w get ln w 60 end 61 emit nl 62 note 3: the word order reversed, words kept 63 for w ulong k 64 if gt w 0 65 emit sp 66 end 67 x = sub sub k 1 w 68 emit part msg get st x get ln x 69 end 70 emit nl 71 ret 0 72 end