1. Docs
  2. Reference

Functions

The functions expressions can call, where each works, and an example of each.

Generated from the engine's spec (HAM 1.7.0), so it always matches what the engine reads.

Functions

NameWhat it does
abs(x) x without its sign.
In particle · abs(-3) → 3
append(list, value, [max]) A new list: list with value added at the end, trimmed to its last max, for a variable that keeps the latest values: $recent = append($recent, $msg, 20).
In text · append('[1, 2]', 3, 2) → [2, 3]
clamp(x, lo, hi) x kept between lo and hi.
In text, condition, style, particle · clamp(130, 0, 100) → 100
cos(x) Cosine.
In particle · cos(0) → 1
ease(x, [ms]) The same as smooth.
In text, condition · ease(7) → 7
floor(x) x rounded down.
In particle · floor(2.7) → 2
format(x, [pattern], [locale]) A number as display text: money, grouping, decimals, percent, compact, or seconds as a clock time.
In text, condition · format(0.124, '+percent:1') → +12.4%, format(1234, 'compact') → 1.2K, format(12345, 'number') → 12,345, format(161, '-time') → -2:41, format(2427.2, 'money') → $2,427.20, format(3725, 'time') → 1:02:05, format(65, 'time') → 1:05
hsl(h, s, l, [a]) A color, for <particles color=>: each part a formula (hsl(i*3 + t*60, 80%, 60%)).
In particle · hsl(0, 100%, 50%) → #FF0000
lerp(a, b, k) The same as mix.
In particle · lerp(10, 20, 0.25) → 12.5
max(a, b, …) The largest of its arguments: a header that shrinks to a floor, h-(max(72, 240 - $scroll.y)).
In text, condition, style, particle · max(72, 240 - 200) → 72
min(a, b, …) The smallest of its arguments.
In text, condition, style, particle · min(240, 72) → 72
mix(a, b, k) Between a and b by k.
In particle · mix(10, 20, 0.5) → 15
mod(x, y) The remainder of x / y (also x % y).
In particle · mod(7, 3) → 1
noise(x, [y], [z]) Smooth noise, 0–1: near points give near values (a flow field: noise(x*0.01, y*0.01, t*0.2)). The same on every run.
In particle · noise(0, 0) → 0.5, round(noise(0.5, 0.5), 3) → 0.375
pow(x, y) x to the power y.
In particle · pow(2, 10) → 1024
random([a], [b], [seed]) random() is a number from 0 up to 1; random(a, b) a whole number from a to b when both are whole (random(1, 6) is a die), else a number between them. Shown, it holds while it is on screen (each call and each loop row its own); in a statement ($roll = random(1, 6)) every run draws afresh.
In text, condition · random(1, 100, 7) → 24, random(5, 5) → 5
rgb(r, g, b, [a]) A color, for <particles color=>, as hsl.
In particle · rgb(0, 128, 255) → #0080FF
round(x, [digits]) x rounded to the nearest whole number, or to digits decimals.
In text, condition, style, particle · round(7.46) → 7, round(7.46, 1) → 7.5
shuffle(list, [seed]) The list in an order drawn at random. Shown (@text, @{…}, a loop source: <@for each="a in shuffle([$q.right, $q.wrong1, $q.wrong2])">) it holds while it is on screen and is new when the markup is parsed again (a navigate, a swap) or the seed changes; in a statement ($deck = shuffle($deck)) every run draws afresh.
In text, condition · shuffle([1, 2, 3, 4, 5], 7) → [4, 5, 3, 1, 2]
sin(x) Sine.
In particle · sin(0) → 0
smooth(x, [ms]) x, eased: when x changes, the value shown glides from the old value to the new over ms (ease-out) instead of jumping. The first value shows at once. In @text, @show, and in an attribute as @{smooth($x, ms)}. ease is the same.
In text, condition · smooth(5, 400) → 5
sqrt(x) Square root (0 for x ≤ 0).
In particle · sqrt(81) → 9
tan(x) Tangent.
In particle · tan(0) → 0

This page is also Markdown, and all of HAM is in llms.txt.