View Source Guesswork.Ast.Statement protocol (Guesswork v0.8.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

call()

@type call() :: (env() -> stream())

env()

stream()

@type stream() :: Enumerable.t(Guesswork.Answer.t() | :halt)

t()

@type t() :: term()

All the types that implement this protocol.

Functions

find_statements(statement, fun)

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

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

resolve(statement, opts)

@spec resolve(t(), Guesswork.Ast.Statement.Opts.t()) :: stream() | call()

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.

Either returns a stream of possible answer sets, or returns a closure that takes an environment and returns a stream of possible answer sets.

simplify(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).

substitute(statement, env)

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

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