procedure spell(n) #: spell out integer (short scale) local m, i static scale initial { scale := [ "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion","septillion"] every scale[i := 1 to *scale ] := [ integer(repl("999",i + 1)), -3 * i, " "||scale[i] ] push(scale,[999,2," hundred"]) } n := integer(n) | stop(image(n)," is not an integer") if n < 0 then return "negative " || spell(-n) if n <= 12 then return { "0zero,1one,2two,3three,4four,5five,6six,7seven,8eight,_ 9nine,10ten,11eleven,12twelve," ? { tab(find(n)) move(*n) tab(find(",")) } } else if n <= 19 then return { spell(n[2] || "0") ? (if ="for" then "four" else tab(find("ty"))) || "teen" } else if n <= 99 then return { "2twen,3thir,4for,5fif,6six,7seven,8eigh,9nine," ? { tab(find(n[1])) move(1) tab(find(",")) || "ty" || (if n[2] ~= 0 then "-" || spell(n[2]) else "") } } else if n <= scale[i := 1 to *scale,1] then return { # generalize based on scale spell(n[1:scale[i,2]]) || scale[i,3] || (if (m := n[scale[i,2]:0]) ~= 0 then " and " || spell(m) else "") } else fail # really big end