Authoring Programmes
A complete guide to writing LOVE-LANG programmes, from base statements to complex multi-phase applications.
Authoring Programmes
Section titled “Authoring Programmes”This guide walks you through writing real LOVE-LANG programmes — from simple key-value statements to multi-phase applications using the full bracket hierarchy.
Programme Structure
Section titled “Programme Structure”A LOVE programme is a sequence of base statements optionally interspersed with decorator directives (@Something). There is no required main function — evaluation proceeds top-to-bottom.
# 1. Imports@Import[Prelude::*]@Import[Invariants::DependencyInjection]
# 2. Configurationname = "My Programme"version = 1.0.0
# 3. Logicresult = [[ + 1 2 3 ]]
# 4. Effects[[[[[ @print result]]]]]Using Imports
Section titled “Using Imports”The @Import directive brings modules into scope:
# Import everything from Prelude@Import[Prelude::*]
# Import a specific invariant@Import[Invariants::DependencyInjection]
# Import a named module@Import[Stdlib::Math]@Import[Stdlib::String]@Import[Stdlib::List]Dependency Injection
Section titled “Dependency Injection”The @DependencyInjection decorator wires dependencies automatically:
@Import[Prelude::*]@Import[Invariants::DependencyInjection]
# Basic DI — just declare the entry point@DependencyInjection[#mode Automatic]init = [#! [args :List[String]] ]In automatic mode, LOVE resolves dependencies by inspecting the type signatures of your functions and injecting matching values from the current scope.
Advanced DI with Aliases
Section titled “Advanced DI with Aliases”@DependencyInjection[#mode Automatic ::alias[AutomaticMode]]init = [#! [args :List[String]] @and[>] result :List = args -> @apply[self] -> @create[List <- args] -> @filter[@and[True]] ]This is the actual ssg.love example from the LOVE-LANG repository — a static site generator bootstrap.
Writing a Data Model
Section titled “Writing a Data Model”Use base statements and type annotations to define your data:
# User modeluser-id @[Number] = 1user-name @[String] = "Alice"user-email @[String] = "[email protected]"user-active @[Boolean] = trueuser-roles @[List] = [:admin :user]Defining Structural Schemas (L3)
Section titled “Defining Structural Schemas (L3)”UserRecord = [[[ id @[Number] name @[String] email @[String] active @[Boolean] roles @[List[Symbol]]]]]
PostRecord = [[[ id @[Number] title @[String] body @[String] author-id @[Number] tags @[List[String]] published @[Boolean]]]]Control Flow
Section titled “Control Flow”LOVE uses S-expression style control flow:
# Conditionalresult = [[ if active "User is active" "User is inactive" ]]
# Unlessfallback = [[ unless active "Default value" ]]
# And / Orall-valid = [[ @and [condition-a condition-b condition-c] ]]any-valid = [[ @or [condition-a condition-b] ]]Pipelines with ->
Section titled “Pipelines with ->”LOVE supports Elixir-style pipeline notation:
processed = args -> @apply[self] -> @create[List <- args] -> @filter[@and[True]]A Complete Programme: User Authentication
Section titled “A Complete Programme: User Authentication”-
Set up imports and effectors
auth.love @Import[Prelude::*]@Import[Invariants::DependencyInjection] -
Define the type contract
UserPayload = [[[name @[String]hash @[String]]]] -
Write the logic
raw_pass = "password123"user_name = "alice"hashed_pass = [[ @hash_pass raw_pass ]] -
Apply the type contract
validated = [[[ UserPayload ]]] {:name user_name:hash hashed_pass} -
Perform the side effect (L5)
[[[[[@sql_write "users" validated]]]]]