Interpolations are enclosed by doubled curly braces {{}}. Regex literals follow the same pattern for interpolations, such as re/{{x}}/.
Newlines are allowed within interpolated sections of strings that allow newlines.
opening/closing marks and examples |
---|
{{ }} "{{var}}" "{{x+y}}" |
Interpolation modifiers are preceded with a colon within an interpolation, such as "{{x:r2}}" to round the printed result of x to 2 places.
Langur allows a single ASCII space on each side of a modifier to improve readability.
You can use multiple modifiers on a single interpolation (chained), and they will be executed in order.
If you want to convert from a number, you must use that modifier first, because after the first one, the rest of the modifiers will be dealing with a string. The exceptions are rounding and truncate modifiers, which return a number.
# example of modifier chaining "{{x:r2:L-20(...):20}}" # r2 rounds to 2 decimal places # L-20(...) limits from left, using "..." as indicator, to 20 code points max # 20 right aligns to 20 code points # so that ... # if x is 1180591620717411303424, you get "...20717411303424.00" # if x is 1234.234, you get " 1234.23"
modifier |
---|
code point alignmentminimumminimum(cp)
"{{x:7}}" "{{x:7(.)}}" "{{x:7(2E)}}" "{{x:-7}}" "{{x:-7(.):20(#)}}" |
code point limitLmaximumLmaximum(...)
Examples: "{{x:L7}}" "{{x:L7(...)}}" "{{x:L7(…)}}" "{{x:L-7}}" "{{x:L20(*)}}" |
grapheme limitLgmaximumLgmaximum(...)
Examples: "{{x:Lg7}}" "{{x:Lg7(...)}}" "{{x:Lg7(…)}}" "{{x:Lg-7}}" "{{x:Lg20(*)}}" |
hexadecimal+X+Xminimum +x +xminimum
Examples: "{{x:x2}}" "{{x:X}}" "{{x:x2:7(.)}}" |
custom base+basex+baseX +basexminimum +baseXminimum
Examples: "{{x:2x}}" "{{x:+11x10}}" |
fixed point+10xinteger.fractional!+10xinteger.fractional- +10xinteger,fractional! +10xinteger,fractional-
Examples: "{{x:10x1.3}}" "{{x:+10x7.3}}" |
scientific notation+1.scale!E+exponentscale+1.scale!e+exponentscale +1.scale-E+exponentscale +1.scale-e+exponentscale +1,scale!E+exponentscale +1,scale!e+exponentscale +1,scale-E+exponentscale +1,scale-e+exponentscale
Examples: "{{x:e}}" "{{x:1.7e}}" "{{x:+E7}}" "{{x:E+}}" "{{x:+1,7e+7}}" |
roundrrscale! rscale-
Examples: "{{x:r}}" "{{x:r2}}" "{{x:r-3}}" "{{x:r3-}}" |
truncatettscale! tscale-
Examples: "{{x:t}}" "{{x:t2}}" "{{x:t-3}}" "{{x:t3!}}" |
custom formatting functionfn fnExamples: val F = fn s:tcase(s[1]) ~ lcase(less(s, of=1)) "{{x:fn F}}" |
code pointscp
Examples: "{{x:cp}}" |
date-timedt(format)dt var
Examples: "{{x:dt(2006)}}" "{{x:dt(+07:00)}}" "{{x:dt(Jan)}}" val format = "Jan 2"; "{{x:dt format}}" |
escape meta-charactersescExamples: "{{x:esc}}" re/{{x:esc}}/ |
type stringTExamples: "{{x:T}}" |