lemma-engine 0.9.5

A pure, declarative language for business rules.
Documentation
spec weather_clothing 2025-01-01
"""
Weather-Based Clothing Recommendation

Shows how rules can make decisions based on conditions.
Simple logic that's easy to understand.
"""

data temperature: measure
  -> unit celsius 1.0
  -> minimum -70 celsius
  -> maximum 70 celsius

data wind_speed: number
  -> minimum 0

data is_raining: boolean

rule clothing_layer: "light"
  unless temperature < 10 celsius then "warm"
  unless temperature < 5 celsius  then "very_warm"
  unless temperature > 25 celsius then "none"

rule needs_jacket: no
  unless temperature < 15 celsius then yes
  unless is_raining               then yes
  unless wind_speed > 20          then yes

rule needs_umbrella: is_raining

rule needs_hat: no
  unless temperature > 25 celsius then yes
  unless temperature < 0 celsius  then yes

rule comfort_level: "comfortable"
  unless temperature < 5 celsius  then "cold"
  unless temperature > 30 celsius then "hot"
  unless is_raining and temperature < 10 celsius
    then "uncomfortable"

rule recommendation:
  "Enjoy your day! You don't need a hat."
  unless comfort_level is "cold"
    then "Dress warmly and stay indoors if possible"
  unless comfort_level is "hot"
    then "Stay hydrated and seek shade"
  unless comfort_level is "uncomfortable"
    then "Consider postponing outdoor activities"