Rete.Engine.Nodes (Rete v0.2.0)

Copy Markdown View Source

What each node kind does when tokens or elements arrive.

Internal. Every clause has the same shape. It takes the state and the items. It returns the new state, and the propagation work produced. The loop in Rete.Engine does the walking, so nothing here calls a child directly.

The retraction rule. A node must retract exactly what it propagated, by value. Downstream memories remove by value, and a mismatch strands a token forever. So a node never propagates from what it was handed. It propagates from what its memory reports, after the memory update. Retracting something never stored produces no downstream work at all.

Two kinds of work are returned as ops, instead of done here. {:retract_facts, node_id, facts} has to re-enter the alpha network. {:event, event} is not a node's business either. See docs/design/engine.md §5.

Summary

Functions

Handles one unit of propagation, returning the state and the work it produced.

Seeds the beta root's empty token, returning the state and the work it produced.

Functions

handle(state, arg)

Handles one unit of propagation, returning the state and the work it produced.

seed_root(state)

Seeds the beta root's empty token, returning the state and the work it produced.

Every child of the beta root is sent one %Rete.Token{} from the left. A RootJoin ignores it. A negation, a collection, or a test in first position has no other way to receive the match it is entitled to.

Does nothing after the first call. A second root token would give every such rule a second support that no retraction ever clears. See docs/design/engine.md §6.