lemma-engine 0.9.7

A pure, declarative language for business rules.
Documentation
spec library_fees
"""
Library Late Fees

Shows conditional logic with unless clauses.
Easy to understand: books returned late incur fees.
"""

uses lemma units

data money: measure
  -> decimals 2
  -> unit eur: 1.00
  -> minimum 0 eur

data book_kind: text
  -> option "regular"
  -> option "reference"
  -> option "new_release"

data book_type:        book_kind
data is_first_offense: boolean
data due_date:         date
data return_date:      date


rule days_overdue:
  due_date...return_date as day as number

rule daily_fee:
  0 eur
  unless book_type is "regular"     then 0.25 eur
  unless book_type is "reference"   then 0.5 eur
  unless book_type is "new_release" then 1 eur

rule is_in_grace_period:
  days_overdue <= 3
  unless book_type is "new_release" then no

rule total_fee:
  days_overdue * daily_fee

rule final_fee:
  total_fee
  unless is_first_offense   then total_fee * 50%
  unless is_in_grace_period then 0 eur

rule can_checkout:
  yes
  unless final_fee > 10 eur then no