Language Reference

The reference describes exactly what each part of L4 is and does. To learn the language step by step, take a course; to get a particular job done, see the tutorials.

Go to If you want to…
Glossary Look up a single keyword or symbol
Cheat sheet Find the L4 version of code you know
Error messages Understand an error or warning
Library Find a function for dates, money or lists (further down the page)

Language

Types

Describe the things your rules talk about: people, contracts, amounts, dates. The overview lists the built-in types (BOOLEAN, NUMBER, STRING, DATE) and the ready-made ones (LIST, MAYBE, EITHER).

Page What it covers
DECLARE Records with HAS, enumerations with ONE OF, computed fields, type synonyms, parameterised types, A and AN
ASSUME A name with a type but no value, for facts supplied from outside; how it works with @export
FOR ALL Functions that work for values of any type
Coercions Converting between NUMBER, STRING, DATE and other types

Functions

Rules in L4 are functions: they take inputs and compute a result.

Page What it covers
DECIDE Define a value, a function or a rule; DECIDE … IF; several clauses, one per case
GIVEN and GIVETH Name and type the inputs; state the type of the result
MEANS The body of a definition, and computed fields in records
LET and WHERE Local definitions, before or after an expression
YIELD Functions without a name
AKA Other names for a definition, a type or a section
Mixfix functions Names with words between the inputs, so a call reads like a sentence

Control flow

Choose between cases.

Page What it covers
IF A choice between two values; several conditions
BRANCH Several conditions checked in order, with an OTHERWISE
CONSIDER Choosing by the shape of a value; missing and redundant branches

Operators

Combine and compare values. The overview covers word and symbol forms (AND or &&), precedence, and AND and OR across several lines (..., ..).

Page What it covers
AND, OR, NOT, IMPLIES Truth tables, conditions over several lines, order of evaluation
UNLESS Exceptions: "A, unless B"
Arithmetic PLUS, MINUS, TIMES, DIVIDED BY, MODULO; exact numbers
Comparisons EQUALS, GREATER THAN, LESS THAN, AT LEAST, AT MOST

Regulative rules

Obligations, permissions and prohibitions: who must, may or must not do what, by when, and what follows. The overview shows the parts of a rule and how to test one with #TRACE.

Page What it covers
PARTY, MUST, MAY, SHANT Who acts, and whether they must, may or must not (MUST NOT); DO
Deadlines and consequences WITHIN, HENCE and LEST, FULFILLED and BREACH, PROVIDED, EXACTLY, RAND and ROR
BECAUSE The reason given for a breach
DEONTIC The type of a regulative rule, and how a rule is evaluated
EVENT What a party did and when; WAITUNTIL

Syntax and directives

How an L4 file is written, on one page:

Library

Built-in functions

Functions every L4 file can use without IMPORT:

Standard libraries

Libraries you load with IMPORT:

Group Libraries
Core prelude (lists, MAYBE, EITHER, pairs), math
Dates and time daydate, time, datetime, timezone, excel-date
Money and finance currency, holdings, actus
Legal entities and places legal-persons, jurisdiction
AI llm

Error messages

What the compiler's errors and warnings mean and how to fix them, grouped by kind: layout and syntax, types, names and imports, definitions and clauses, pattern matching, regulative rules and export.