Your First Rule
How to become a rule-maker
1.1 A Single Legal Obligation
Let's start with something every lawyer understands: a simple legal obligation.
Example: "A registered charity must file an annual return."
In L4, like in legal documents, we need to first set up the basic types and terms:
IMPORT prelude
-- Define basic types first. More on this later.
DECLARE RegisteredCharity
HAS name IS A STRING
registrationNumber IS A STRING
isRegistered IS A BOOLEAN
DECLARE Actor IS ONE OF
CharityActor HAS charity IS A RegisteredCharity
DECLARE Action IS ONE OF
FileAnnualReturn
-- Now we can write our first legal obligation
GIVEN charity IS A RegisteredCharity
GIVETH A CONTRACT Actor Action
`charity annual return obligation` MEANS
PARTY CharityActor charity
MUST FileAnnualReturn
WITHIN 365
HENCE FULFILLED
Try it out in the online-editor
Let's break this down:
IMPORT prelude
- Imports basic L4 functions we use in this projectDECLARE
statements - Define the types we'll useGIVEN charity IS A RegisteredCharity
- This rule applies to registered charitiesGIVETH A CONTRACT Actor Action
- This function returns a contractPARTY CharityActor charity
- The charity is the one with the obligationMUST FileAnnualReturn
- This is what they must doWITHIN 365
- They have 365 daysHENCE FULFILLED
- What happens when they comply
Try it yourself: Write a rule that says "A solicitor must maintain client confidentiality."
1.2 Adding Conditions and Consequences
Real legal rules have conditions and consequences. Let's make our charity rule more realistic:
GIVEN charity IS A RegisteredCharity
GIVETH A CONTRACT Actor Action
`charity conditional return obligation` MEANS
IF charity's isRegistered EQUALS TRUE
THEN PARTY CharityActor charity
MUST FileAnnualReturn
WITHIN 60 -- 2 months in days
HENCE FULFILLED
LEST FULFILLED
ELSE FULFILLED
New elements:
IF charity's isRegistered EQUALS TRUE
- Adds a condition using proper boolean comparisonWITHIN 60
- Sets a deadline (60 days = approximately 2 months)HENCE FULFILLED
- What happens if they complyLEST FULFILLED
- What happens if they don't complyELSE FULFILLED
- Alternative path if condition not met
The Legal Logic: This captures the complete legal structure: who, what, when, and consequences.
1.3 Your First Simulation
Let's test our rule with some data:
-- Define Date type first
DECLARE Date
HAS year IS A NUMBER
month IS A NUMBER
day IS A NUMBER
-- Define Purpose type
DECLARE Purpose IS ONE OF
`advancement of animal welfare`
`advancement of education`
-- Update RegisteredCharity with all needed fields
DECLARE RegisteredCharity
HAS name IS A STRING
registrationNumber IS A STRING
registrationDate IS A Date
address IS A STRING
purposes IS A LIST OF Purpose
isRegistered IS A BOOLEAN
-- Create a test charity
DECIDE testCharity IS RegisteredCharity "Animal Welfare Society" "CH001" (Date 2020 1 15) "Jersey" (LIST `advancement of animal welfare`) TRUE
-- The charity now exists and can be used in rules
What This Does: L4 can calculate that this charity must file by February 28, 2024 (2 months after December 31, 2023).
Success Check: You can now write a basic legal obligation, add conditions and deadlines, and test it with data.
Last updated