Standard libraries
The standard libraries are L4 files that ship with every l4 binary, the editor extension and Legalese Cloud. They are written in L4 and add functions for lists, dates, money, legal entities and more. Nothing from them is available until you IMPORT it, not even the prelude.
Functions built into the language, such as TOSTRING, CONCAT or FETCH, need no import: see Built-in functions.
Libraries
Core
- prelude: lists, MAYBE and EITHER values, pairs and dictionaries.
- math:
exp, logarithms, square roots and trigonometry that giveNOTHINGinstead of failing on bad input.
Dates and time
- daydate: build, compare and shift dates; weekdays, ISO weeks, months and leap years. Its page also covers
date-compat, the olderDATE d m yspelling. - time: time of day without a date or time zone, in 24-hour or AM/PM form.
- datetime: a date, a time and a time zone together, compared across time zones.
- timezone: constants such as
SGTandESTfor IANA time zone names. - excel-date: Excel date serials and
DATEDIF,DAYS360,YEARFRAC,EDATE,EOMONTH,WORKDAYandNETWORKDAYS.
Money and finance
- currency: amounts in whole minor units (cents) with ISO 4217 currency codes.
- holdings: cap tables, vesting, convertible notes and SAFEs, liquidation preferences and valuations.
- actus: ACTUS financial contract types, events, day count conventions and schedules.
Legal entities and places
- legal-persons: names, addresses, identity documents, age and legal capacity, corporate entities and beneficial ownership.
- jurisdiction: ISO 3166 country and subdivision codes, with checks and conversions.
AI
- llm: call Anthropic, OpenAI or OpenRouter models over HTTP.
IMPORT
IMPORT makes the definitions of another L4 file available in the current file. Put the IMPORT lines at the top of the file, before the first § section, one module per line. An IMPORT below a section heading is ignored without a warning: the names it should bring in are then reported as not defined.
Example:
-- IMPORT examples
-- One module per line, at the top of the file.
IMPORT prelude
IMPORT math
IMPORT daydate
-- A name with a hyphen goes in backticks.
IMPORT `legal-persons`
-- prelude: list functions
#EVAL sum (LIST 1, 2, 3)
-- math: functions that give NOTHING instead of failing
#EVAL sqrt 16
#EVAL sqrt (0 - 1)
-- daydate: dates
#EVAL `the day after` (Date 31 12 2024)
-- legal-persons: age on a given date
#EVAL `age in years` (Date 15 3 1990) (Date 1 1 2025)
IMPORT prelude
IMPORT daydate
IMPORT `legal-persons`
Module names
- A module is named by its file name without
.l4:IMPORT daydateloadsdaydate.l4. - A name with a hyphen goes in backticks:
IMPORT `excel-date`,IMPORT `legal-persons`,IMPORT `date-compat`. Without them,IMPORT excel-dateis a parse error ("unexpected -"). IMPORTtakes a module name, not a path or a quoted string.IMPORT "helpers.l4"is a parse error, and a folder in front of the name is ignored:IMPORT `rules/helpers`looks forhelpers.l4.
What an import gives you
- Every top-level definition of the imported file: its types, constructors, functions and constants.
- Nothing is imported for you. A file that uses
map,sumorfromMaybeneedsIMPORT preludelike any other library. - What a library imports also reaches your file:
IMPORT datetimegives youdaydatetoo, andIMPORT daydategives youdate-compat. Importing each library you use by name still makes a file easier to read.
Where modules are found
For IMPORT helpers, L4 uses the first of these that exists:
helpers.l4in your project's root folder, or in the folder of the file that writes theIMPORT.- The standard library built into the
l4you are running. It needs no files on disk and always matches thatl4.
So a file of your own with the name of a standard library, such as prelude.l4 beside your rules, is used instead of the standard one. Operators and library developers can change the search with the JL4_LIBRARY_PATH environment variable; How IMPORT finds libraries gives the full order, what Legalese Cloud does, and the warning shown when two different copies of a module are visible. When nothing is found, the error is Module not found.