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

column_list

(Table, Text) → [a]

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.

column_set

(Table, Text) → #{a}

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.

table_records

Table → [Record]

Get the list of table rows represented as records.

vertical_lookup_list

(Table, Text, Text, a) → [b]

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.

vertical_lookup_first

(Table, Text, Text, a) → b

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_duplicates

[a] → [a]

Remove duplicate elements from a list.

get

(Record, Text) → a

Get the value of a field in a record or table.

min_list

[a] → a

Get the minimum value in a list.

max_list

[a] → a

Get the maximum value in a list.

sum_list

[a] → a

Get the sum of a list.

product_list

[a] → a

Get the product of a list.

or_list

[YesNo] → YesNo

Get the logical OR of a list.

and_list

[YesNo] → YesNo

Get the logical AND of a list.

days

Int → DateDuration

Make a date duration from a number of days.

months

Int → DateDuration

Make a date duration from a number of months.

years

Int → DateDuration

Make a date duration from a number of years.

num_days

(Date, Date) → Int

Get the number of days between two dates.

num_months

(Date, Date) → Int

Get the number of months between two dates.

num_years

(Date, Date) → Int

Get the number of years between two dates.

period

(Date, Date) → Period

Build a period between two dates.

min

(a, a) → a

Get the minimum of two numbers. ↓

max

(a, a) → a

Get the maximum of two numbers. ↓

not

YesNo → YesNo

Get the logical NOT of a boolean.

find_closest

([a], a) → a

Given a value and two candidates, return the candidate that is closest to the value.

abs

a → a

Get the absolute value of a number. ↓

floor

(a, Int) → a

Round a number down towards negative infinity to the nearest number with the given number of decimal precision.

ceiling

(a, Int) → a

Round a number up towards positive infinity to the nearest number with the given number of decimal precision.

round

(a, Int) → a

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. ↓

floor0

a → a

Round a number down to the nearest integer. See floor.

ceiling0

a → a

Round a number up to the nearest integer. See ceiling.

round0

a → a

Round a number to the nearest integer. See round.

round2

a → a

Round a number to the nearest number with two decimal places. See round.

elem

(a, [a]) → YesNo

Check if an element is in a list.

member

(a, #{a}) → YesNo

Check if an element is in a set.

length

a → Int

Get the length of a sized container (e.g. list, set, lookup, text). ↓

from_year

Year → Int

Convert a year to an integer.

from_integer

Int → a

Convert an integer to a number of any other number type.

from_number

Number → a

Convert a floating point to a number of any other format.

from_percent

Percent → a

Convert a percentage to a number of any other format. ↓

from_decimal

Decimal → a

Convert a decimal to a number of any other format.

from_text

Text → a

Convert a text to a compatible format (e.g. CaselessText, Uuid).

from_text_optional

Text → a?

Convert a text to a compatible format (e.g. CaselessText, Uuid), or null if the conversion fails.

to_percent

a → Percent

Convert a number to a percentage. For example, to_percent(1) returns 100% and to_percent(0.5) returns 50%. ↓

to_text

a → Text

Convert a compatible value to a text.

to_date

a → Date

Convert a compatible value to a date. ↓

to_decimal

a → Decimal

Convert a number to a decimal. ↓

list_to_set

[a] → #{a}

Convert a list to a set.

set_to_list

#{a} → [a]

Convert a set to a list.

head

[a] → a

Get the first element of a list.

last

[a] → a

Get the last element of a list.

tail

[a] → [a]

Get all but the first element of a list.

zip

([a], [b]) → [{a: a, b: b}]

Zip two lists together. ↓

some

a → a?

Wrap a value into an optional.

is_subset_of

(#{a}, #{a}) → YesNo

Check if a set is a subset of another set.

is_null

a → YesNo

Check if a value is null.

mod

(a, b) → c

Get the remainder of a division.

exp

Number → Number

Get the exponential of a number. ↓

log

Number → Number

Get the natural logarithm of a number. ↓

log10

Number → Number

Get the base 10 logarithm of a number.

log_gamma

Number → Number

Get the log gamma of a number. ↓

concat

→ [a]

Concatenate a list of lists.

append

([a], [a]) → [a]

Append two lists.

concat_text

[Text] → Text

Concatenate a list of texts.

intercalate_text

(Text, [Text]) → Text

Intercalate a list of texts with a separator.

replace_text

(Text, Text, Text) → Text

Replace all occurrences of a substring in a text.

sha256

Text → Text

Get the SHA256 hash of a text. ↓

number_format

(Int, Number) → Text

Pretty print number to given decimal places.

ignore_case

Text → CaselessText

Convert a text to a caseless text.

lookup

(a, Lookup<a,b>) → b

Lookup a value in a lookup (map).

lookup_raw

(a, Lookup<a,b>) → Text

Lookup a value in a lookup (map) returning a raw text value.

lookup_optional

(a, Lookup<a,b>) → b?

Lookup a value in a lookup (map), returning null if the key is not present or value is invalid.

lookup_grid

(a, b, Grid<a,b,c>) → c

Lookup a value in a grid (map of maps). See lookup.

lookup_grid_raw

(a, b, Grid<a,b,c>) → Text

Lookup a value in a grid (map of maps) returning a raw text value. See lookup_raw.

transpose_grid

Grid<a,b,c> → Grid<b,a,c>

Transpose a grid.

lookup_keys

Lookup<a,b> → #{a}

Get all keys of a lookup (map).

lookup_values

Lookup<a,b> → [b]

Get all values of a lookup (map).

insert

(a, b, Lookup<a,b>) → Lookup<a,b>

Insert a value into a lookup (map).

delete

(a, Lookup<a,b>) → Lookup<a,b>

Delete a value from a lookup (map).

cons

(a, [a]) → [a]

Prepend an element to a list.

wait

Promise<a> → a

Immediately returns a value if promise is resolved, otherwise blocks evaluation. The promise could be resolved later.

broker_code

Umr → Text

Get the broker ID as Text from a UMR.

linear_interpolate

([Number], [Number], Number) → Number

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.

uuid_v5

(Uuid, Text) → Uuid

Generate a UUID v5 with the provided namespace and name.

is_infix_of

(a, a) → YesNo

Check if a text is a substring of another text.

take

(Int, a) → a

Take the first n items of a sequence (eg. list or text).

take_end

(Int, a) → a

Take the last n items of a sequence (eg. list or text).

drop

(Int, a) → a

Drop the first n items of a sequence (eg. list or text).

drop_end

(Int, a) → a

Drop the last n items of a sequence (eg. list or text).

words

Text → [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.

year_of

Date → Int

Get the year of a date.

month_of

Date → Int

Get the month of a date.

day_of_month

Date → Int

Get the day of a date.

obstacles

Trace → Trace

Get all obstacles in a trace.

sort

[a] → [a]

Sort a list or an ordered set of items.

rsort

[a] → [a]

Reverse sort a list or an ordered set of items.

reverse

[a] → [a]

Reverse a list or an ordered set of items.

index_of

([a], a) → Int

Get the index of an element in an ordered container.

enumerate

[a] → [{index: Int, item: a}]

Enumerate a list with zero-based indices.

lookup_from_list

[{key: a, value: b}] → Lookup<a,b>

Build lookup from a list of key-value pairs. In case of duplicates the last value is used.

sin

Number → Number

Get the sine of a number

cos

Number → Number

Get the cosine of a number

tan

Number → Number

Get the tan of a number

atan2

(Number, Number) → Number

Get angle of a coordinate

sqrt

Number → Number

Get the square root of a number

degrees_to_radians

Number → Number

Convert a number from degrees to radians

radians_to_degrees

Number → Number

Convert a number from radians to degrees

clamp

(a, a, a) → a

Clamp a number between two values. ↓

format_time

(Text, Time) → Text

Format a Date or Time as text based on a formatting string. We following the Haskell formatTime formatting.

to_lower

Text → Text

Convert text to lowercase.

to_upper

Text → Text

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

foldl

((b, a) → b, b, [a]) → b

Fold a list from left to right. ↓

foldr

((a, b) → b, b, [a]) → b

Fold a list from right to left. ↓

sort_on

(a → b, [a]) → [a]

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

optional

Produces an optional value, returns null if evaluation has obstacles.

datapoint

Returns a reference to a datapoint without evaluating it.

invalid

Return a custom error message in the trace and invalidate the policy.

document

Construct a document from a name and parts.

document_part_from_template

Construct a document part from a mustache template.

document_part_from_static_pdf

Construct a document part from a static PDF.

needs_collecting

Indicates that a datapoint needs to be collected.

undefined

Generate a trace with an optional error message.

evaluate_across_inforce_intervals

For a bound quote, return values over time intervals (endorsement-aware). Only usable in @overall context.

value_at_binding

Value of an @overall expression at the given bound quote. Only from @version context.

value_before_current_layer

Value of an @overall expression before the current layer. Only from @version context.

Constants

Constants represent literal values available by default, such as null, today, or an empty lookup. They are simple, context-independent values.

Name Description

null

The null value.

today

The current date (today).

empty_lookup

An empty lookup (map).

empty_ranged_lookup

An empty ranged lookup (map).

Dates

Dates are predefined symbolic bindings to meaningful dates in the policy or quote lifecycle.

Name Description

version_inforce_date

The version inforce date.

version_outforce_date

The version outforce date.

Identifiers

Core identifiers available in the evaluation context.

Name Description

submission_id

The submission ID.

quote_id

The quote ID.

Other

Name Description

policy_created

The policy creation time.

Debugging

These primitives are intended for inspection or testing in development environments.

Use only in REPL or console.
Name Description

explain

Generate a trace (explanation) of computing a value.

short_explain

Generate a human-readable explanation of computing a value.

still_required

Find all required datapoints in a trace.

relevant

Find all relevant datapoints in a trace.

violations

Find all violations in a trace.

Deprecated

These primitives are no longer recommended for use and may be removed in future versions.

Name Description

list_key_args

Experimental. May be removed.

result_only

Use the @shallow annotation instead.

first

Use head() instead.

policy_start_date

Use policy.start_date datapoint instead. To default to policy creation date use to_date(policy_created).

policy_end_date

Use policy.end_date datapoint instead. To default to policy creation date use to_date(policy_created).