Skip to content

Built-in Symbols

FuncScript registers every built-in helper under the symbols documented below. Symbol lookup is case-insensitive, so the canonical names listed here can be written in any casing. Wherever an operator has both infix and function-call forms, you can use either (1 + 2 or +(1, 2)).

Arithmetic Operators

  • +, -, *, /, % – Standard arithmetic on integers, long integers, and floats. Pure integer chains stay integral as long as each division is exact; otherwise values promote to floating point automatically.
  • div – Integer-only division; accepts only 32/64-bit integers (or their long forms) and truncates toward zero. Mixing with non-integers raises a type mismatch error.
  • - value – Unary negation for numeric values.

Comparison & Membership

  • =, ==, !=, <, <=, >, >= – Comparisons returning Boolean values (== is an alias for =).
  • value in list – Membership test for lists (for strings use Contains(text, substring)).

Null & Safe Access Operators

  • value ?? fallback – Returns fallback when value is null.
  • kvc?.key – Safe member access; returns null when the target is null or the key is missing (errors when the target is not a record).
  • test-val?!expr – Evaluates expr if test-val is not null; otherwise, defaults to null. This is typically used when expr depends on a non-null test-val.
  • kvc.key – Direct member access (returns null for missing keys; errors on null targets and non-records).

Logical & Control Flow

  • if condition then value else other – Branching expression (keywords are required).
  • a and b / a or b – Logical conjunction/disjunction with short-circuit evaluation.
  • ! value – Logical negation.
  • switch selector, match1: result1, match2: result2, defaultResult – Switch over a selector; each match: result arm is compared to the selector and the first match wins. Add an optional trailing default value (without :) to return when no match occurs.
  • case condition: result – Conditional helper written with condition: result pairs separated by commas or semicolons; add a true: fallback arm or a trailing default value (case cond: value, fallback) for defaults.

Numeric Functions

All numeric helpers belong to the math provider collection, so you can call them either directly (Sqrt(9)) or via the namespace-style accessor (math.Sqrt(9)). Aliases such as Ceil and log also work under the math scope.

  • math.Abs(number) (Abs) – Absolute value.
  • math.Ceiling(number) (Ceiling, alias math.Ceil) – Smallest integer greater than or equal to number.
  • math.Floor(number) (Floor) – Largest integer less than or equal to number.
  • math.Round(number, digits?) (Round) – Round to the nearest integer or to digits decimals.
  • math.Trunc(number) (Trunc) – Drop the fractional component.
  • math.Sign(number) (Sign) – Return -1, 0, or 1.
  • math.Clamp(value, min, max) (Clamp) – Constrain to a range.
  • math.Min(value1, value2, ...) / math.Max(...) (Min / Max) – Extremes across numeric arguments.
  • math.Pow(base, exponent) (Pow, alias math.Power, operator ^) – Raise base to exponent or chain powers (2 ^ 3 ^ 2).
  • math.Sqrt(number) / math.Cbrt(number) (Sqrt / Cbrt) – Square or cube roots.
  • math.Exp(number) (Exp) – Euler's number raised to number.
  • math.Ln(number, base?) (Ln, alias math.log) – Natural logarithm, with optional custom base.
  • math.Log10(number) / math.Log2(number) (Log10 / Log2) – Base-10 or base-2 logarithms.
  • math.Sin(number) / math.Cos(number) / math.Tan(number) (Sin / Cos / Tan) – Trigonometric functions (radians).
  • math.Asin(number) / math.Acos(number) / math.Atan(number) (Asin / Acos / Atan) – Inverse trigonometric functions.
  • math.Atan2(y, x) (Atan2) – Two-argument arctangent preserving quadrant information.
  • math.Sinh(number) / math.Cosh(number) / math.Tanh(number) (Sinh / Cosh / Tanh) – Hyperbolic trig functions.
  • math.Asinh(number) / math.Acosh(number) / math.Atanh(number) (Asinh / Acosh / Atanh) – Inverse hyperbolic trig functions.
  • math.DegToRad(degrees) / math.RadToDeg(radians) (DegToRad / RadToDeg, aliases deg2rad / rad2deg) – Convert angles.
  • math.Random(seed) (Random) – Deterministic pseudo-random double in [0, 1) derived from seed.
  • Constants exposed via provider collections are accessed without parentheses (e.g., math.Pi).

List & Sequence Helpers

  • list map (value, index) => ... – Transform each element.
  • list filter (value, index) => ... – Keep elements that satisfy the predicate.
  • list reduce (acc, value) => ... ~ seed – Accumulate a list into a single value.
  • Range(start, count) (Series) – Produce [start, start+1, ...] with count elements; start may be any numeric type and controls the output element type, while count is coerced to an integer by truncating toward zero.
  • Distinct(list) – Remove duplicate values while preserving order.
  • Any(list, predicate) – Returns true when any element satisfies predicate.
  • Contains(listOrText, value) – Returns true when value is present (lists) or value is a substring (strings, case-insensitive).
  • First(list, predicate) – Returns the first element that matches predicate (or null when none match).
  • Len(value) (Length) – Length of the list or string; null returns 0; any other scalar returns 1.
  • Take(list, count) / Skip(list, count) – Subset operators.
  • Sort(list) – Sort values using default comparison.
  • Reverse(list) – Reverse the order of elements.

Key-Value & Record Helpers

  • Member access uses dot syntax (record.key). For selecting a subset of fields, see the selector syntax described in Syntax.

Text & Formatting

  • text.upper(text) – Convert text to uppercase (culture invariant).
  • text.lower(text) – Convert text to lowercase (culture invariant).
  • join(list, separator) – Concatenate list entries with separator.
  • format(value, format?) – Convert value to a string; format can be a numeric pattern like "#,0.00" or the special "json" mode.
  • find(text, value, startIndex?) – Return the zero-based index of value or -1 if not found.
  • regex(text, pattern, flags?) – Returns true when pattern matches text; optional flags accepts characters such as i, m, s, or x to toggle regex options.
  • substring(text, start, length?) – Slice from text starting at start with optional length.
  • endswith(text, suffix) – Returns true when text ends with suffix.
  • isBlank(value) – Returns true when a string is null, empty, or whitespace.
  • parse(text, format?) – Parse text using helpers like "hex", "l" (int64), or "fs" (nested FuncScript).
  • _templatemerge(value1, value2, ...) – Internal templating helper that flattens values (lists or scalars) into a single string.
  • HEncode(text) – HTML-encode text.

Date & Time

  • Date(text, format?) – Parse a date string, optionally with a custom .NET format string.
  • TicksToDate(ticks) – Convert .NET ticks (int64) to a DateTime value.

File & OS Helpers

  • file(path) – Read a file as text.
  • isfile(path) – Returns true when a path points to a file.
  • fileexists(path) – Returns true when a path exists and is a file.
  • dirlist(path) – Return the entries inside a directory.

Diagnostics & Miscellaneous

  • log(value, messageOrHandler?) – Returns value after writing either the formatted value (when the second argument is omitted) or the provided messageOrHandler output. When a handler function is supplied it is invoked with value.
  • error(message) – Constructs an Error value. Most built-in functions propagate an Error result, which aborts evaluation when consumed without handling.

Values & Constants

  • math.Pi – π constant.
  • math.E – Euler's constant.