Skip to main content

Modeling a world

Facts and state​

If you need…Write…Meaning
A starting factgiven room is occupiedEvidence loaded before execution.
Mutable stateslot door.position: closed | open = closedOne current value from its domain.
An observationinput badge: valid | expiredThe caller supplies it; live effects cannot write it.
A fact with several participantsrelation delivered(sender, listener)Use given delivered(i, you) for a delivery that already happened, or add delivered(i, you) to record one during a run.
A quantityslot balance: int = 100Use set balance = balance - price to update it. int is exact; float uses finite binary64 values.

An omitted badge proves neither badge is valid nor badge is not valid. An observed expired badge proves both badge is expired and badge is not valid. For ordinary facts, negation needs its own evidence.

Derive a fact or change the state?​

given room is occupied
slot room.power: on | off = on
rule lighting(x):
x is occupied and x.power is on => x has light

claim(room has light)
switch room.power from on to off

After the switch, claim(room has light) would fail because the rule requires power. claim(room has not light) would also fail: no rule or fact says the room lacks light.

Group effects that must succeed together in an action. Put requires before the effects. Use can(...) to test the action without committing its changes or events. emit records an event; add records a relationship that rules can use.

Try an alternative without committing it​

input you.presence: present | gone
given i has light

suppose you.presence is present:
i give you carrying light
claim(you has light)

claim(i has light)

The gift happens only inside suppose, so i still has the light afterward. To give it away in the live run, use when you.presence is present: instead.

give moves a property. grant copies it. With share, the recipient has the property only while the source holds it. If either participant declares presence, it must be present for the transfer to succeed.

Lists and sets​

slot currents: list<AC | DC> = [AC, DC, AC]
slot modes: set<AC | DC> = {DC, AC, DC}
claim(length(currents) == 3 and length(modes) == 2)
claim(all(current in currents: current in modes))
for current in currents:
emit measured(current)

A list keeps its order and duplicates. A set visits each distinct value once, in a deterministic order. for uses the items present when the loop starts. all and any check conditions without committing effects. An empty collection satisfies all but not any; an unknown collection proves neither.

slot steps: list<int> = 0..10 starts the list at 0 and stops before 10.

Both list<has fire> and set<has fire> require evidence that each member has fire. If an effect would invalidate that evidence, it raises list_invalidated(). An action can remove a member and put out its fire together.

Named records​

record Reading:
amps: int
mode: AC | DC

slot readings: set<record Reading> = {Reading{amps: 12, mode: AC}}
claim(any(reading in readings: reading.amps > 10 and reading.mode is AC))

Fields can hold scalars, other records, lists, sets, or subjects that must satisfy an evidence type. Read fields with dot notation. Use set to replace a record slot as a whole. An effect that breaks an evidence field in a record slot raises record_invalidated().

Check a general property​

relation delivered(sender, listener)
relation received_light(listener)
rule receipt_of(s, l):
delivered(s, l) => received_light(l)

theorem delivery_establishes_receipt(s, l):
given delivered(s, l)
prove received_light(l)

check verifies the theorem from its local premise. It creates no live delivery. Use a claim during execution to test whether one particular listener actually received light.

The full syntax guide covers numeric comparisons, existential witnesses, finite cases, repetition, recovery, scope, and termination checks.