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/sovereign-intelligence/blob/main/harness/examples/loops.om # sovereign-intelligence Front door to Drake Stapleton's sovereign stack. 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 `sovereign-intelligence / harness / examples / loops.om` 70 lines ยท 1401 bytes Raw Blame History 1 note loops: while COND bound N (N 1..`9223372036854775807`), for i T K [bound N], break and continue 2 note ---- output helpers: a function works on a global by naming it (a global is never an argument) 3 global ob uchar 32 4 note outb: write ob[off .. off+n) to stdout; a short write continues, 0 or an error exits 90 5 note bound: every pass writes at least one byte and n <= 32, so at most 32 passes 6 fn outb off ulong n ulong to void 7 e = add off n 8 p = off 9 while lt p e bound 32 10 k = write 1 ob p sub e p 11 if le k 0 12 exit 90 13 end 14 p = add p ulong k 15 end 16 end 17 note putu: v in decimal, then a newline. A ulong has at most 20 digits, so 20 passes 18 fn putu v ulong to void 19 i = ulong 31 20 put ob 31 10 21 n = v 22 while true bound 20 23 i = sub i 1 24 put ob i uchar add rem n 10 48 25 n = div n 10 26 if eq n 0 27 break 28 end 29 end 30 outb i sub 32 i 31 end 32 note putl: a signed value; -(v+1)+1 avoids negating the minimum, which would trap 1 33 fn putl v long to void 34 if lt v 0 35 put ob 0 45 36 outb 0 1 37 putu add ulong neg add v 1 1 38 ret 39 end 40 putu ulong v 41 end 42 note collatz: the step count to reach 1; the bound is a stated limit, not a proof, so exceeding it traps 4 43 fn collatz n ulong to ulong 44 x = n 45 c = ulong 0 46 while ne x 1 bound 1000 47 c = add c 1 48 if eq rem x 2 0 49 x = div x 2 50 continue 51 end 52 x = add mul x 3 1 53 end 54 ret c 55 end 56 fn main to int 57 putu collatz 27 58 s = ulong 0 59 for i ulong 100 60 if eq rem i 3 0 61 continue 62 end 63 if gt i 50 64 break 65 end 66 s = add s i 67 end 68 putu s 69 ret 0 70 end