Your First Rule

How to become a rule-maker

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 project

  • DECLARE statements - Define the types we'll use

  • GIVEN charity IS A RegisteredCharity - This rule applies to registered charities

  • GIVETH A CONTRACT Actor Action - This function returns a contract

  • PARTY CharityActor charity - The charity is the one with the obligation

  • MUST FileAnnualReturn - This is what they must do

  • WITHIN 365 - They have 365 days

  • HENCE FULFILLED - What happens when they comply

Indentation matters in L4! It is used to signal the language parser a closer belonging/contextual dependency to the previous term. In engineering speak: Something more indented is a property of or parameter for an above-written/less indented instruction context or function

Try it yourself: Write a rule that says "A solicitor must maintain client confidentiality."

Answer
DECLARE Solicitor
    HAS name IS A STRING
        licenseNumber IS A STRING

DECLARE Actor IS ONE OF
    SolicitorActor HAS solicitor IS A Solicitor

DECLARE Action IS ONE OF
    MaintainConfidentiality

GIVEN solicitor IS A Solicitor
GIVETH A CONTRACT Actor Action
`solicitor confidentiality obligation` MEANS
  PARTY SolicitorActor solicitor
  MUST MaintainConfidentiality
  WITHIN 365
  HENCE FULFILLED

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 comparison

  • WITHIN 60 - Sets a deadline (60 days = approximately 2 months)

  • HENCE FULFILLED - What happens if they comply

  • LEST FULFILLED - What happens if they don't comply

  • ELSE 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