Rete.Token (Rete v0.1.0)

Copy Markdown View Source

A partial match travelling down the beta network: what a rule has established so far.

Internal, but its fields reach you through Rete.Listener events. Read them freely. Do not depend on its functions.

  • :matches[{fact, node_id}], in match order. Order is part of the token's identity. Two tokens over the same facts in a different order are different matches.
  • :bindings%{name => value}, the variables bound so far.

Tokens are compared by value, which is what makes retraction work when the fact that caused it is a different term with the same value.

Summary

Functions

Extends a token with one more matched fact and the bindings it contributed.

The facts behind a token, in match order.

The subset of a token's bindings used as a join key.

Types

t()

@type t() :: %Rete.Token{
  bindings: %{required(atom()) => term()},
  matches: [{term(), term()}]
}

Functions

extend(token, fact, node_id, bindings)

@spec extend(t(), term(), term(), %{required(atom()) => term()}) :: t()

Extends a token with one more matched fact and the bindings it contributed.

iex> Rete.Token.extend(%Rete.Token{}, {:order, 1}, :n3, %{cid: 1})
%Rete.Token{matches: [{{:order, 1}, :n3}], bindings: %{cid: 1}}

facts(token)

@spec facts(t()) :: [term()]

The facts behind a token, in match order.

iex> token = %Rete.Token{matches: [{{:customer, 1}, :n1}, {{:order, 1, 250}, :n3}]}
iex> Rete.Token.facts(token)
[{:customer, 1}, {:order, 1, 250}]

join_key(token, keys)

@spec join_key(t(), [atom()]) :: %{required(atom()) => term()}

The subset of a token's bindings used as a join key.

iex> token = %Rete.Token{bindings: %{cid: 1, amt: 5}}
iex> Rete.Token.join_key(token, [:cid])
%{cid: 1}