View Source Guesswork.Ast.Statement protocol (Guesswork v0.6.0)

A Statement is a semantically complete value. It is in no way required to be logically consistent.

Summary

Types

t()

All the types that implement this protocol.

Functions

Searches all clauses of the statement looking for values that match the predicate.

Takes a statement (ideally non-concrete) and a knowledge base and attempts to find any permutations of bindings for the variables that are true according to the knowledge base and statement.

Attempts to simplify the statement into a less nested operation and returns nil if the statement holds no logical information.

Takes an environment (a mapping of variables to entities) and substitutes the entities into any place the variable is.

Types

@type t() :: term()

All the types that implement this protocol.

Functions

Link to this function

find_statements(statement, fun)

View Source
@spec find_statements(t(), (t() -> bool())) :: [t()]

Searches all clauses of the statement looking for values that match the predicate.

Link to this function

resolve(statement, opts)

View Source

Takes a statement (ideally non-concrete) and a knowledge base and attempts to find any permutations of bindings for the variables that are true according to the knowledge base and statement.

@spec simplify(t()) :: t() | nil

Attempts to simplify the statement into a less nested operation and returns nil if the statement holds no logical information.

Note that the only requirement for this function is that the input and output statements are logically equivalent, not that the result is the shallowest possible answer (in practice its quite 'greedy' so it is unlikely to produce the 'best' answer, just better).

Link to this function

substitute(statement, env)

View Source
@spec substitute(t(), env()) :: t()

Takes an environment (a mapping of variables to entities) and substitutes the entities into any place the variable is.