Squiggly

Numbers

abs, ceil, floor, round, max, min, sum, int, float, bool, printf.

Squiggly’s numeric type is BigDecimal — every numeric literal and every arithmetic operator yields one. The builtins below operate on that and on values that can be coerced to it.

Math

FunctionAritySignatureWhat
abs1abs nAbsolute value
ceil1ceil nSmallest integer ≥ n
floor1floor nLargest integer ≤ n
round1round nHalf-away-from-zero rounding to integer
max2max a bThe larger of two
min2min a bThe smaller of two
sum1sum xsSum a list of numbers

Parse & coerce

FunctionAritySignatureWhat
number1number sParse a string as BigDecimal
int1int vTruncate toward zero; parses strings
float1float vFull-precision numeric; parses strings
bool1bool vSquiggly’s truthiness rule — empty string/list/map → false, zero → false, otherwise true

Formatted output

FunctionAritySignatureWhat
printf1+printf fmt args...Java Formatter-style — %d / %05d / %,d / %.2f / %-10s / %x / %%

Examples

{{ abs -5 }}                    5
{{ ceil 3.2 }}                  4
{{ round 3.5 }}                 4
{{ max 7 12 }}                  12
{{ sum [1, 2, 3, 4] }}          10

{{ int 3.9 }}                   3        (truncates, doesn't round)
{{ int '42' }}                  42       (parses strings)
{{ float '3.14' }}              3.14
{{ bool '' }}                   false
{{ bool 0 }}                    false
{{ bool 'no' }}                 true     (non-empty string)

{{ printf '%05d'    42 }}             00042
{{ printf '%,d'     1234567 }}        1,234,567
{{ printf '%.2f'    3.14159 }}        3.14
{{ printf '%-10s|'  'hi' }}           hi        |
{{ printf '%s = %d' 'count' 7 }}      count = 7

How printf picks Java types

printf walks the format string once, matches each %-conversion to its argument in order, and widens BigDecimal arguments to either Long (when the conversion is in the dboxX family) or Double (otherwise). That means printf '%d' 7 and printf '%f' 3.5 both work without manual int 7 / float 3.5 coercions in the template.

Use %% for a literal %. Unknown conversions surface a Java IllegalFormatConversionException at render time — squiggly doesn’t sanity-check the pattern.

Search

Esc
to navigate to open Esc to close