Cheatsheet
One page covering everything, for scanning or bookmarking. Each area has its own page with the full detail.
Every example below is executed against the engine when the documentation is built, so if one of them is wrong the build fails rather than the page quietly going stale.
Arithmetic
Section titled “Arithmetic”2 + 2 * 10 // 22(2 + 3) * 4 // 202^10 // 1,02417 mod 5 // 22.5k // 2,5003M // 3,000,000Note that % means percent, not modulo. Use mod or modulo for remainder.
Writing 17 % 5 is a parse error rather than 2, because 17 % is already a
complete expression.
Percentages
Section titled “Percentages”10% of 250 // 25increase 100 by 10% // 110.00100 to 150 // 50.00%5% of what is 6 // 120100cm + 2m // 300.00 cm1 km + 500 m // 1.50 km5 km to miles // 3.11 miles1 hour to minutes // 60 minutes72F to C // 22.22 C20C in F // 68.00 FFunctions
Section titled “Functions”sqrt(16) // 4max(3, 7) // 7round(3.7) // 4gcd(12, 18) // 6hex(255) // 0xFFbin(5) // 0b101Statistics and phrasing
Section titled “Statistics and phrasing”average of 10, 20, 30 // 20median of 1, 5, 3 // 3larger of 10 and 4 // 10half of 50 // 25clamp 15 between 1 and 10 // 10Conversions
Section titled “Conversions”255 as hex // 0xFF255 as binary // 0b111111110.5 as % // 50.00%0.75 as fraction // 3/4Programmer math
Section titled “Programmer math”0xFF // 2550b1010 // 100o17 // 151 << 8 // 2560xFF & 0x0F // 150xF0 | 0x0F // 25512 xor 10 // 61 KiB in bytes // 1024.00 bytesConditionals
Section titled “Conditionals”5 > 3 // true10 == 10 // truetrue and false // falseif 5 > 3 then 100 else 200 // 100Variables and functions
Section titled “Variables and functions”Colon-prefixed names are explicit. A bare name works too.
:a = 10:b = 20:a + :b // 30f(x) = 2*x + 1f(5) // 11Matrices and vectors
Section titled “Matrices and vectors”[1,2;3,4] // [1, 2; 3, 4][1,2,3] * 10 // [10, 20, 30][1,2,3] + [10,20,30] // [11, 22, 33][1,2,3][0] // 1[1,2;3,4]^T // [1, 3; 2, 4]det([1,2;3,4]) // -2Ranges, map and reduce
Section titled “Ranges, map and reduce”A range is written start:end. It is only recognised inside brackets or a
function call, because a bare 0:3 is a clock time. See
map, reduce and aggregates.
map(10*x, 0:3) // [0, 10, 20, 30]sum(x, 0:4) // 10sum(x, [10, 20, 30]) // 60reduce(acc+x, [1,2,3]) // 6prod(x, [2,3,4]) // 24Symbolic
Section titled “Symbolic”An unknown stays an unknown rather than becoming an error.
1+2+b+3+b => // 2b+6x^2+3x+2 => // x^2+3x+2Algebra
Section titled “Algebra”expand((x+1)*(x+2)) // x^2+3x+2factor(x^2-4) // (x-2)*(x+2)solve(x^2-4=0, x) // [-2, 2]solve(2x+6=0, x) // -3cancel((x^2-1)/(x-1)) // x+1apart((3x+5)/(x^2-1)) // 4/(x-1)-1/(x+1)An equation with one unknown can also be written on its own line.
x^2-4 = 0x => // [-2, 2]Complex numbers
Section titled “Complex numbers”3i // 3i1i*1i // -1sqrt(-4) // 2iconj(2+3i) // 2-3isolve(x^2+1=0, x) // [-i, i]Calculus
Section titled “Calculus”der(x^3, x) // 3x^2integral(x^2, x) // 1/3x^3taylor(sin(x), x=0, 5) // 1/120x^5-1/6x^3+xjacobian(x*y, x+y) // [y, x; 1, 1]$100 + $50 // $150.0010 dollars // $10.00tax on 100 at 20% // 20Currency conversion such as 10 USD to GBP reaches the network, so it resolves
asynchronously rather than returning a value immediately. See
async and live data.
Dates and times
Section titled “Dates and times”Results depend on the current date, so these are shown rather than asserted.
| Expression | Result |
|---|---|
25/12/2023 + 20 days | Sunday, January 14, 2024 |
next friday | the date of the coming Friday |
days until 25/12/2026 | the number of days, as a duration |
9:00am + 3 hours | 12:00:00 PM on the current day |
7:30 to 20:45 | 795 minutes |
Bigger integers
Section titled “Bigger integers”123n * 2 // 246Comments and headings
Section titled “Comments and headings”A line starting with # is a heading and evaluates to nothing. Text after //
is a comment.
2 + 2 // comment // 4A label followed by a colon is kept, and the expression after it is evaluated.
total: 5 + 3 // 8