Documentation Menu · A first application in ten minutes
A first application in ten minutes
Build a tool-lending workshop in five verified steps—with zero loops, identity allocation, or manual locks.
cache.hector)
Build a small tool-lending workshop in five steps. Each step is a complete program that adds a new fact to the previous one. You write no loop, identity allocation or lock; each step shows what Hector does for you.
1. Things and their fields #
Declare tools with a name and a daily price, and the person who can see them. Hector assigns identities and shows each tool's name and price without a query written by you.
-- but: un atelier prête ses outils ; chaque outil a un nom et un tarif journalier
Clerk
Tool name: Text, daily: Money
show name, daily to Clerk within 1 s
2. Status and transitions #
A loan starts out on loan and can then be returned. Declare the event that creates it and the event that returns it. Hector refuses to return a loan that is no longer out, without a guard or a flag written by you.
-- but: un atelier prête ses outils ; un prêt est sorti, puis rendu
Clerk
Tool name: Text, daily: Money
show name, daily to Clerk within 1 s
Loan tool: Tool, borrower: Text
status: Out | Returned
-> Out on Lend by Clerk
Out -> Returned on Return by Clerk
show status to Clerk within 1 s
3. A total that maintains itself #
A loan's cost is its number of days times the tool's price; a tool's revenue is the sum of returned loans' costs. Write each calculation once: Hector derives it from the facts and calculates what an observer reads.
-- but: un atelier prête ses outils ; le coût d'un prêt et le revenu d'un outil se déduisent
Clerk
Tool name: Text, daily: Money
income = sum(loans.cost where Returned)
show name, income to Clerk within 1 s
Loan tool: Tool, borrower: Text, days: Count
status: Out | Returned
cost = days * tool.daily
-> Out on Lend by Clerk
Out -> Returned on Return by Clerk
show status, cost to Clerk within 1 s
4. A law that becomes a refusal #
A tool cannot be on loan more times than its stock, and a loan lasts at least one day. Write those limits as laws. Hector derives a refusal for a loan that would exceed stock, and finds that returning needs no guard. A show gives the manager the count on loan and the revenue.
-- but: un atelier ne prête jamais un outil plus souvent qu'il n'en possède ; un prêt dure au moins un jour
Clerk
Tool name: Text, daily: Money, stock: Count
lent = count(loans where Out)
income = sum(loans.cost where Returned)
law lent <= stock
show name, lent, stock to Clerk within 1 s
show income to Clerk within 1 s
Loan tool: Tool, borrower: Text, days: Count
status: Out | Returned
cost = days * tool.daily
law days >= 1
-> Out on Lend by Clerk
Out -> Returned on Return by Clerk
show status, cost to Clerk within 1 s
5. Examples tell a story #
An example tells a case one fact per line: Ana borrows the only drill, Bob is refused, Ana returns it, and Bob then borrows it. Each see gives an expected result calculated from the price: a wrong figure makes the check fail. The events do not need a written by here because the manager's role is derived.
-- but: un atelier ne prête jamais un outil plus souvent qu'il n'en possède ; un prêt dure au moins un jour
Clerk
Tool name: Text, daily: Money, stock: Count
lent = count(loans where Out)
income = sum(loans.cost where Returned)
law lent <= stock
show name, lent, stock to Clerk within 1 s
show income to Clerk within 1 s
Loan tool: Tool, borrower: Text, days: Count
status: Out | Returned
cost = days * tool.daily
law days >= 1
-> Out on Lend by Clerk
Out -> Returned on Return by Clerk
show status, cost to Clerk within 1 s
example un outil, deux emprunteurs
p = Tool(name: "Perceuse", daily: 12 EUR, stock: 1)
p1 = Lend(tool: p, borrower: "Ana", days: 3)
see p1 is Out
see p1.cost = 36 EUR
see p.lent = 1
refused Lend(tool: p, borrower: "Bob", days: 2)
Return(p1)
see p1 is Returned
see p.income = 36 EUR
see p.lent = 0
p2 = Lend(tool: p, borrower: "Bob", days: 2)
see p2.cost = 24 EUR
see p.lent = 1
see p.income = 36 EUR
example durée nulle
s = Tool(name: "Scie", daily: 8 EUR, stock: 2)
refused Lend(tool: s, borrower: "Eve", days: 0)
see s.lent = 0
see s.income = 0 EUR