Primitive functions and values
This page lists all primitive functions, constants, and identifiers available in Brossa. These primitives are the foundational building blocks of expressions and evaluation logic in the language.
Primitives fall into several categories:
-
Functions perform computations or data transformations. For example,
sum_list,lookup,abs. -
Constants represent fixed values. For example,
null,today. -
Special operations are primitives that do not behave like regular functions, often inspecting or controlling the evaluation of their input. For example,
document,optional. -
Identifiers and Dates refer to specific values in the evaluation context. For example,
submission_id,policy_start_date. -
Debugging contains tools primarily for trace inspection and should only be used in REPL or console environments.
-
Deprecated lists primitives that are no longer recommended for use.
| Select ↓ after a description in the tables below to navigate to an example of that primitive. |
Functions
Functions are used in expressions. They operate on values like lists, numbers, dates, and text, and include operations such as arithmetic, logic, list manipulation, and conversions.
| Name | Type | Description |
|---|---|---|
|
|
Given a table and a column, returns a list of values in that column, in row-order. The column is given as a string literal. |
|
|
Given a table and a column, returns a set of values in that column, in row-order. The column is given as a string literal. |
|
|
Get the list of table rows represented as records. |
|
|
Given two column names and a scalar, looks for the scalar in the first column and returns all scalars in the same row for the second column. |
|
|
Given two column names and a scalar, looks for the first scalar in the first column and returns the corresponding value in the second column. |
|
|
Remove duplicate elements from a list. |
|
|
Get the value of a field in a record or table. |
|
|
Get the minimum value in a list. |
|
|
Get the maximum value in a list. |
|
|
Get the sum of a list. |
|
|
Get the product of a list. |
|
|
Get the logical OR of a list. |
|
|
Get the logical AND of a list. |
|
|
Make a date duration from a number of days. |
|
|
Make a date duration from a number of months. |
|
|
Make a date duration from a number of years. |
|
|
Get the number of days between two dates. |
|
|
Get the number of months between two dates. |
|
|
Get the number of years between two dates. |
|
|
Build a period between two dates. |
|
|
Get the minimum of two numbers. ↓ |
|
|
Get the maximum of two numbers. ↓ |
|
|
Get the logical NOT of a boolean. |
|
|
Given a value and two candidates, return the candidate that is closest to the value. |
|
|
Get the absolute value of a number. ↓ |
|
|
Round a number down towards negative infinity to the nearest number with the given number of decimal precision. |
|
|
Round a number up towards positive infinity to the nearest number with the given number of decimal precision. |
|
|
Round a number to the nearest number with the given number of decimal precision. In the case of equidistant candidates the even one is returned. ↓ |
|
|
Round a number down to the nearest integer.
See |
|
|
Round a number up to the nearest integer.
See |
|
|
Round a number to the nearest integer.
See |
|
|
Round a number to the nearest number with two decimal places.
See |
|
|
Check if an element is in a list. |
|
|
Check if an element is in a set. |
|
|
Get the length of a sized container (e.g. list, set, lookup, text). ↓ |
|
|
Convert a year to an integer. |
|
|
Convert an integer to a number of any other number type. |
|
|
Convert a floating point to a number of any other format. |
|
|
Convert a percentage to a number of any other format. ↓ |
|
|
Convert a decimal to a number of any other format. |
|
|
Convert a text to a compatible format (e.g. |
|
|
Convert a text to a compatible format (e.g. |
|
|
Convert a number to a percentage.
For example, |
|
|
Convert a compatible value to a text. |
|
|
Convert a compatible value to a date. ↓ |
|
|
Convert a number to a decimal. ↓ |
|
|
Convert a list to a set. |
|
|
Convert a set to a list. |
|
|
Get the first element of a list. |
|
|
Get the last element of a list. |
|
|
Get all but the first element of a list. |
|
|
Zip two lists together. ↓ |
|
|
Wrap a value into an optional. |
|
|
Check if a set is a subset of another set. |
|
|
Check if a value is null. |
|
|
Get the remainder of a division. |
|
|
Get the exponential of a number. ↓ |
|
|
Get the natural logarithm of a number. ↓ |
|
|
Get the base 10 logarithm of a number. |
|
|
Get the log gamma of a number. ↓ |
|
Concatenate a list of lists. |
|
|
|
Append two lists. |
|
|
Concatenate a list of texts. |
|
|
Intercalate a list of texts with a separator. |
|
|
Replace all occurrences of a substring in a text. |
|
|
Get the SHA256 hash of a text. ↓ |
|
|
Pretty print number to given decimal places. |
|
|
Convert a text to a caseless text. |
|
|
Lookup a value in a lookup (map). |
|
|
Lookup a value in a lookup (map) returning a raw text value. |
|
|
Lookup a value in a lookup (map), returning null if the key is not present or value is invalid. |
|
|
Lookup a value in a grid (map of maps).
See |
|
|
Lookup a value in a grid (map of maps) returning a raw text value.
See |
|
|
Transpose a grid. |
|
|
Get all keys of a lookup (map). |
|
|
Get all values of a lookup (map). |
|
|
Insert a value into a lookup (map). |
|
|
Delete a value from a lookup (map). |
|
|
Prepend an element to a list. |
|
|
Immediately returns a value if promise is resolved, otherwise blocks evaluation. The promise could be resolved later. |
|
|
Get the broker ID as Text from a UMR. |
|
|
Takes two lists and a number, find the range this number falls in and linearly interpolate the value. Obstructed if the value is not in any range. |
|
|
Generate a UUID v5 with the provided namespace and name. |
|
|
Check if a text is a substring of another text. |
|
|
Take the first n items of a sequence (eg. list or text). |
|
|
Take the last n items of a sequence (eg. list or text). |
|
|
Drop the first n items of a sequence (eg. list or text). |
|
|
Drop the last n items of a sequence (eg. list or text). |
|
|
Words breaks a text up into a list of words, which were delimited by white space. This function trims any white spaces at the beginning and at the end. |
|
|
Get the year of a date. |
|
|
Get the month of a date. |
|
|
Get the day of a date. |
|
|
Get all obstacles in a trace. |
|
|
Sort a list or an ordered set of items. |
|
|
Reverse sort a list or an ordered set of items. |
|
|
Reverse a list or an ordered set of items. |
|
|
Get the index of an element in an ordered container. |
|
|
Enumerate a list with zero-based indices. |
|
|
Build lookup from a list of key-value pairs. In case of duplicates the last value is used. |
|
|
Get the sine of a number |
|
|
Get the cosine of a number |
|
|
Get the tan of a number |
|
|
Get angle of a coordinate |
|
|
Get the square root of a number |
|
|
Convert a number from degrees to radians |
|
|
Convert a number from radians to degrees |
|
|
Clamp a number between two values. ↓ |
|
|
Format a |
|
|
Convert text to lowercase. |
|
|
Convert text to uppercase. |
Examples
abs
Use abs to ensure a number is always positive, commonly needed for distances or magnitudes.
Usage:
abs(1)
abs(-1)
Returns:
1 : Int 1 : Int
clamp
Use clamp to keep values within acceptable ranges, like ensuring percentages stay between 0-100 or scores within valid bounds.
Usage:
clamp(0, 1, 2)
clamp(3, 1, 2)
Returns:
1 : Int 2 : Int
exp
Use exp for exponential growth calculations, compound interest, or when working with natural logarithms in mathematical formulas.
Usage:
log(exp(5))
Returns:
5.0 : Number
from_percent
Use from_percent to convert percentage values (like 20%) into decimal numbers (0.2) for mathematical calculations.
Usage:
from_percent(20%)
Returns:
0.2 : Number
length
Use length to count items in lists, check if containers are empty, or validate input sizes.
Usage:
length_([])
length_([1,2,3])
Returns:
0 : Int 3 : Int
log
Use log for logarithmic scaling, time series analysis, or mathematical calculations involving exponential relationships.
Usage:
log(exp(5))
Returns:
5.0 : Number
log_gamma
Use log_gamma for statistical calculations and probability distributions, particularly in Bayesian analysis and advanced mathematics.
Usage:
log_gamma(1.0) == 0.0
log_gamma(2.0) == 0.0
round(log_gamma(2.5), 6)
log_gamma(0)
log_gamma(-1)
round(log_gamma(10), 6)
Returns:
yes : YesNo yes : YesNo 0.284683 : Number Either NaN or Infinity value Either NaN or Infinity value 12.801827 : Number
max
Use max to find the larger value when comparing options, setting minimum thresholds, or ensuring values don’t go below a limit.
Usage:
max(1, 2)
Returns:
2 : Int
min
Use min to find the smaller value when comparing options, setting maximum limits, or ensuring values don’t exceed a threshold.
Usage:
min(1, 2)
Returns:
1 : Int
round
Use round to format numbers for display, ensure consistent precision in financial calculations, or clean up floating-point arithmetic results.
Usage:
round(log_gamma(2.5), 6)
Returns:
0.284683 : Number
sha256
Use sha256 to create unique fingerprints of text data, verify data integrity, or generate consistent identifiers from variable content.
Usage:
sha256("foo")
Returns:
"2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae" : Text
to_date
Use to_date to parse date strings or convert other formats into proper date objects for date arithmetic and comparisons.
Usage:
to_date(y)
to_date("2021-09-13")
Returns:
2021-01-01 : Date 2021-09-13 : Date
to_decimal
Use to_decimal to convert different number types into precise decimal format, essential for accurate financial calculations.
Usage:
to_decimal(no)
to_decimal(yes)
to_decimal(6)
Returns:
0d : Decimal 1d : Decimal 6d : Decimal
to_percent
Use to_percent to display decimal values (like 0.5) as readable percentages (50%) in reports and user interfaces.
Usage:
to_percent(0.5)
Returns:
50% : Percent
zip
Use zip to combine related data from two separate lists into paired records, useful for processing parallel datasets.
Usage:
zip([1, 2, 3], [4, 5, 6])
Returns:
[{a: 1, b: 4}, {a: 2, b: 5}, {a: 3, b: 6}] : [{a: Int, b: Int}]
Higher-order functions
Higher-order functions take another function as an input. They perform higher-level operations that may involve evaluation context or state, such as folding over lists.
| Name | Type | Description |
|---|---|---|
|
|
Fold a list from left to right. ↓ |
|
|
Fold a list from right to left. ↓ |
|
|
Sort a list or an ordered set of items based on results of a key function. |
Examples
foldl
Use foldl to accumulate results across a list, such as summing values, building totals, or combining elements into a single result.
Usage:
foldl((total, x) => total + x, 0, [1, 2, 3])
Returns:
6 : Int
foldr
Use foldr to accumulate results across a list from the end, useful when order matters or for building nested structures.
Usage:
foldr((x, total) => total + x, 0, [1, 2, 3])
Returns:
6 : Int
Special operations
Special operations are primitives that do not behave like regular functions. Unlike standard Brossa functions, which evaluate all their arguments before the function itself is applied, special operations often inspect or control the evaluation of their inputs.
They are used for:
-
Controlling evaluation flow (e.g.,
optional,needs_collecting) -
Working with unevaluated expressions (e.g.,
datapoint,undefined) -
Constructing structured outputs (e.g.,
document,document_part_from_template)
Because of their nonstandard behavior, these forms often require a specific context or usage pattern.
| Name | Description |
|---|---|
|
Produces an optional value, returns null if evaluation has obstacles. |
|
Returns a reference to a datapoint without evaluating it. |
|
Return a custom error message in the trace and invalidate the policy. |
|
Construct a document from a name and parts. |
|
Construct a document part from a mustache template. |
|
Construct a document part from a static PDF. |
|
Indicates that a datapoint needs to be collected. |
|
Generate a trace with an optional error message. |
|
For a bound quote, return values over time intervals (endorsement-aware).
Only usable in |
|
Value of an |
|
Value of an |
Constants
Constants represent literal values available by default, such as null, today, or an empty lookup.
They are simple, context-independent values.
| Name | Description |
|---|---|
|
The null value. |
|
The current date (today). |
|
An empty lookup (map). |
|
An empty ranged lookup (map). |
Dates
Dates are predefined symbolic bindings to meaningful dates in the policy or quote lifecycle.
| Name | Description |
|---|---|
|
The version inforce date. |
|
The version outforce date. |
Identifiers
Core identifiers available in the evaluation context.
| Name | Description |
|---|---|
|
The submission ID. |
|
The quote ID. |
Debugging
These primitives are intended for inspection or testing in development environments.
| Use only in REPL or console. |
| Name | Description |
|---|---|
|
Generate a trace (explanation) of computing a value. |
|
Generate a human-readable explanation of computing a value. |
|
Find all required datapoints in a trace. |
|
Find all relevant datapoints in a trace. |
|
Find all violations in a trace. |
Deprecated
These primitives are no longer recommended for use and may be removed in future versions.
| Name | Description |
|---|---|
|
Experimental. May be removed. |
|
Use the |
|
Use |
|
Use |
|
Use |