Rete.IR.Fact (Rete v0.1.0)

Copy Markdown View Source

A single fact condition, e.g. {:order, id, amt}, %Order{id: id} or f = {:order, id} when amt > 0.

Fields are typed by t/0. Three are not obvious:

  • :fact_binding is not part of :bind, because the alpha does not return it. The engine adds it when it builds a token.
  • :bind excludes _-prefixed names, pinned values and module attributes.
  • :join_filter, :join_bind and :new_bind are nil after parsing. Rete.DSL.Bindings fills them in. See docs/design/ir.md §2.

Summary

Types

Raw quoted fragments kept for the later phases: the pattern as written without the fact binding or the when guard, the guard AST or nil, the variable AST of every entry of :bind, and the whole element as written for error messages.

t()

Types

ast()

@type ast() :: %{
  pattern: Macro.t(),
  guard: Macro.t() | nil,
  bind: %{required(atom()) => Macro.t()},
  source: Macro.t()
}

Raw quoted fragments kept for the later phases: the pattern as written without the fact binding or the when guard, the guard AST or nil, the variable AST of every entry of :bind, and the whole element as written for error messages.

t()

@type t() :: %Rete.IR.Fact{
  __ast__: ast() | nil,
  alpha: Rete.IR.Expr.t(),
  bind: [atom()],
  fact_binding: atom() | nil,
  join_bind: [atom()] | nil,
  join_filter: Rete.IR.Expr.t() | nil,
  new_bind: [atom()] | nil,
  type: atom() | module()
}