View Source Guesswork.Answer.Binding (Guesswork v0.6.0)

A 'bound' entity, that is a possible values (notted or exact) and computations, connected to a variable.

Summary

Functions

Applies the env to any computations stored in the binding. If any results disagree, the action fails and nil is returned. Any incomplete computation is ignored.

Takes two bindings and attempts to merge them. Any disagreement between the two will result in failure.

Takes a value and produces a readable string.

Types

@type t() :: %Guesswork.Answer.Binding{
  computations: [{Guesswork.Answer.Computation.t(), boolean()}],
  value: value()
}
@type value() ::
  {:bound, Guesswork.Ast.Term.entity()}
  | {:not, [Guesswork.Ast.Term.entity()]}
  | :unbound

Functions

Link to this function

add_computation(binding, computation, negated)

View Source
@spec add_computation(t(), Guesswork.Answer.Computation.t(), boolean()) :: t()
Link to this function

apply(binding, env, query_id)

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

Applies the env to any computations stored in the binding. If any results disagree, the action fails and nil is returned. Any incomplete computation is ignored.

@spec merge(t(), t()) :: t() | nil

Takes two bindings and attempts to merge them. Any disagreement between the two will result in failure.

Examples

iex> four = Guesswork.Answer.Binding.new(4, false)
...> Guesswork.Answer.Binding.merge(four, four)
four
iex> five = Guesswork.Answer.Binding.new(5, false)
...> Guesswork.Answer.Binding.merge(four, five)
nil
iex> not_five = Guesswork.Answer.Binding.new(5, true)
...> Guesswork.Answer.Binding.merge(four, not_five)
four
iex> not_four = Guesswork.Answer.Binding.new(4, true)
...> Guesswork.Answer.Binding.merge(not_four, not_five)
%Guesswork.Answer.Binding{value: {:not, [4, 5]}}
iex> var = Guesswork.Ast.Variable.new("x")
...> comp = Guesswork.Answer.Computation.new([var], fn x -> x + 4 end)
...> comp_binding = Guesswork.Answer.Binding.new(comp, true)
...> Guesswork.Answer.Binding.merge(four, comp_binding)
%Guesswork.Answer.Binding{value: {:bound, 4}, computations: [{comp, true}]}
@spec value_to_string(value()) :: String.t()

Takes a value and produces a readable string.