View Source Guesswork.Answer (Guesswork v0.6.0)

Answers are maps of variable id to bindings as well as any tests that must be checked.

Summary

Functions

Takes an answer set and removes any binding not passed to the function.

Extracts the displayable information from the answer set, returning a simple map.

Pulls all bound, concrete values from the answer set.

Resolves both tests and computations as well as checking if the stop conditions have been met and the answer stream should halt.

Attempts to use any bound values stored in the answer set to resolve stored computations. Any disagreement found in the new bindings returns a nil.

Checks if the answer set indicates that a stop condition has been met. If a stop condition is met, :halt is returned.

Checks that all tests pass, ignoring any incomplete computation. If the computable tests do not pass, nil is returned.

Replaces all bound variables using the variable id to variable map.

Takes two answer sets and attempts to take the union of them. If any variables point to contradicting values the process will fail and return nil.

Types

@type bindings() :: %{required(String.t()) => Guesswork.Answer.Binding.t()}
@type t() :: %Guesswork.Answer{
  bindings: bindings(),
  query_id: String.t() | nil,
  stop_conditions: [Guesswork.Answer.Computation.t()],
  tests: [Guesswork.Answer.Test.t()]
}

Functions

Link to this function

filter_bindings(answer, kept_ids)

View Source
@spec filter_bindings(t() | :halt, [String.t()]) :: t() | :halt

Takes an answer set and removes any binding not passed to the function.

:halts are passed through to facilitate stop conditions.

@spec flatten(t()) :: %{required(String.t()) => Guesswork.Answer.Binding.value()}

Extracts the displayable information from the answer set, returning a simple map.

@spec get_env(t()) :: Guesswork.Ast.Statement.env()

Pulls all bound, concrete values from the answer set.

@spec new(String.t() | nil) :: t()
Link to this function

put_binding(answer, variable, value, negated)

View Source
@spec put_binding(
  t(),
  Guesswork.Ast.Variable.t(),
  Guesswork.Ast.Term.entity() | Guesswork.Answer.Computation.t(),
  boolean()
) :: {:ok, t()} | :error
Link to this function

put_stop_condition(answer, condition)

View Source
@spec put_stop_condition(t(), Guesswork.Answer.Computation.t()) :: t()
@spec put_test(t(), Guesswork.Answer.Test.t()) :: t()
@spec resolve(t() | :halt) :: t() | :halt | nil

Resolves both tests and computations as well as checking if the stop conditions have been met and the answer stream should halt.

:halts are passed through to facilitate stop conditions.

Link to this function

resolve_computations(answer, env \\ nil)

View Source
@spec resolve_computations(t(), nil | Guesswork.Ast.Statement.env()) :: t() | nil

Attempts to use any bound values stored in the answer set to resolve stored computations. Any disagreement found in the new bindings returns a nil.

Link to this function

resolve_stop_conditions(answer)

View Source
@spec resolve_stop_conditions(t()) :: {t(), Guesswork.Ast.Statement.env()} | :halt

Checks if the answer set indicates that a stop condition has been met. If a stop condition is met, :halt is returned.

Link to this function

resolve_tests(answer, env)

View Source
@spec resolve_tests(t(), Guesswork.Ast.Statement.env()) :: t() | nil

Checks that all tests pass, ignoring any incomplete computation. If the computable tests do not pass, nil is returned.

Link to this function

substitue_variables(answer, var_map)

View Source
@spec substitue_variables(t() | :halt, %{
  required(String.t()) => Guesswork.Ast.Variable.t()
}) ::
  t() | :halt

Replaces all bound variables using the variable id to variable map.

:halts are passed through to facilitate stop conditions.

@spec union(t() | :halt, t() | :halt) :: t() | nil | :halt

Takes two answer sets and attempts to take the union of them. If any variables point to contradicting values the process will fail and return nil.

:halts are passed through to facilitate stop conditions.