| 1 | <h2>Hello, world!</h2> |
| 2 | |
| 3 | <pre><code>"Hello, world!"</code></pre> |
| 4 | |
| 5 | <h2>Lambda functions</h2> |
| 6 | |
| 7 | <h3>Increment</h3> |
| 8 | |
| 9 | <pre><code>5 [7+]! . {Outputs 12.}</code></pre> |
| 10 | |
| 11 | <h3>Square numbers</h3> |
| 12 | |
| 13 | <pre><code>[$*] s: 7s;! . {Outputs 49.}</code></pre> |
| 14 | |
| 15 | <h2>Conditions</h2> |
| 16 | |
| 17 | <h3>Equal, less, or greater than</h3> |
| 18 | |
| 19 | <pre><code>5x: |
| 20 | 7y: |
| 21 | x;y;= |
| 22 | $ |
| 23 | x; |
| 24 | . |
| 25 | [" equals "]? |
| 26 | ~[ |
| 27 | x;y;> |
| 28 | $ |
| 29 | [" is greater than "]? |
| 30 | ~[" is less than "]? |
| 31 | ]? |
| 32 | y; |
| 33 | .</code></pre> |
| 34 | |
| 35 | <h2>Loops</h2> |
| 36 | |
| 37 | <h3>English alphabet</h3> |
| 38 | |
| 39 | <pre><code>'Ai: 'Zm: 1m;+ m: [m;i;>][i;, 1i;+ i:]#</code></pre> |
| 40 | |
| 41 | <h3>Ten Green Bottles</h3> |
| 42 | |
| 43 | <pre><code>[$ . " green bottle" 1> ["s"]? ". |
| 44 | "] f: |
| 45 | 10n: [n;0>][n;f;! n;1- n:]#</code></pre> |
| 46 | |
| 47 | <h2>User input</h2> |
| 48 | |
| 49 | <h3>Reverse a string</h3> |
| 50 | |
| 51 | <pre><code>"Enter the string character by character (or a space to finish): |
| 52 | "0i: [ß ^ $ 32=~][i;1+ i:]# % "Reverse: " [i;0>][, i;1- i:]#</code></pre> |