odoyle.rules

*match*

Provides a map of all the matched values from inside a :then block. This is no longer necessary, because it is accessible via `match` directly.

*session*

Provides the current value of the session from inside a :then or :then-finally block. This is no longer necessary, because it is accessible via `session` directly.

(->rule rule-name rule)

(->rule [rule-name parsed-rule])

Returns a new rule. In most cases, you should use the `ruleset` macro to define rules, but if you want to define rules dynamically, you can use this function instead. See the README section "Defining rules dynamically". The one-argument arity is only meant for internal use.

(->session)

Returns a new session.

(add-rule session rule)

Adds a rule to the given session.

(contains? session id attr)

Returns true if the session contains a fact with the given id and attribute.

(fire-rules session)

(fire-rules session opts)

Fires :then and :then-finally blocks for any rules whose matches have been updated. The opts map may contain: :recursion-limit - Throws an error if rules recursively trigger this many times. The default is 16. Pass nil to disable the limit entirely.

(insert session [id attr value])

(insert session id attr->value)

(insert session id attr value)

Inserts a fact into the session. Can optionally insert multiple facts with the same id. Note: if the given fact doesn't match at least one rule, it will be discarded.

Examples

Insert facts separately
(-> session (insert 1 :todo/text "Wash the car") (insert 1 :todo/done false) (insert 2 :todo/text "Buy groceries") (insert 2 :todo/done false) query-all)
Insert facts batched by id
(-> session (insert 1 {:todo/text "Wash the car", :todo/done false}) (insert 2 {:todo/text "Buy groceries", :todo/done false}) query-all)

(insert! id attr->value)

(insert! id attr value)

Equivalent to: (o/reset! (o/insert o/*session* id attr value))

(query-all session)

(query-all session rule-name)

When called with just a session, returns a vector of all inserted facts. Otherwise, returns a vector of maps containing all the matches for the given rule.

Examples

Query all the facts from the session
(query-all session)
Query the matches for a rule
(query-all session :odoyle.examples/get-todo)

(remove-rule session rule-name)

Removes a rule from the given session.

(reset! new-session)

Mutates the session from a :then or :then-finally block.

(retract session id attr)

Retracts the fact with the given id + attr combo.

(retract! id attr)

Equivalent to: (o/reset! (o/retract o/*session* id attr))

(wrap-rule rule {what-fn :what, when-fn :when, then-fn :then, then-finally-fn :then-finally})

Wraps the functions of a rule so they can be conveniently intercepted for debugging or other purposes. See the README section "Debugging".