A rule says when these facts are present, this follows. Nobody calls a rule: it fires when the store makes it true, and firing repeats until nothing more matches.
Bondy has two kinds:
- A derivation rule adds new relation facts from existing ones, written with
:-("if"). It only ever adds, so it always finishes (stratification takes care ofnot). This is Datalog. - A rewrite rule matches constraints in a store and uses
removeto say which matched facts are taken out, andtellto add constraints and events. The facts it does not remove stay. This is Constraint Handling Rules (CHR), the language Thom Frühwirth created in 1991.[1]
bondy
rule consume_token =
on Request(id: rid) as req, Bucket(id: rid, tokens: t, max_tokens: m) as bucket
remove req, bucket
when t > 0
tell Bucket(id: rid, tokens: t - 1, max_tokens: m),
Allowed(id: rid, remaining: t - 1)
endA rule's when guard must be pure, deterministic and total, and its result must not go from true to false as more facts arrive. The compiler checks all of these.
Thom Frühwirth, "Theory and Practice of Constraint Handling Rules", Journal of Logic Programming 37(1–3), 1998, and Constraint Handling Rules, Cambridge University Press, 2009. ↩︎