Rete.IR.Production (Rete v0.9.0)

Copy Markdown View Source

A rule or a query.

t/0 types every field. Three are not obvious:

  • :name names the production, but the generated RHS function is rhs_name/1 of it instead — a query owns its own name in its module.
  • :bind comes from the classified LHS, via lhs_bindings/1. So it excludes a negation's variables, and it is the union over a disjunction's branches. A variable only some branches bind is not in every token, so the RHS reads it defensively.
  • :params is what the head of a query binds: the keys of its matches. It is always [] on a rule. Unlike :bind, it holds only guaranteed bindings, which are the keys that every match carries. It is sorted.
  • :head is the head of a query as it was written, one string per pattern. The patterns themselves are AST, so they stay in __ast__.head for the code generator and go no further. Only a message needs them after that, and a message needs the source rather than the AST. So this is what survives escape/1 and reaches the network.
  • :rhs is nil until the production is escaped. The engine logically inserts and truth-maintains its return value. nil or [] inserts nothing.

Summary

Types

t()

@type t() :: %Rete.IR.Production{
  __ast__: map() | nil,
  bind: [atom()],
  hash: integer(),
  head: [String.t()],
  lhs: Rete.IR.lhs(),
  module: module(),
  name: atom(),
  opts: keyword(),
  params: [atom()],
  rhs: (integer(), map() -> any()) | nil,
  type: :rule | :query
}