View Source Guesswork.Constraint.Comparison (Guesswork v0.8.0)

Simple 2-ary comparisions of terms implemented as a Guesswork.Constraint.

Equality vs. Other Constraints

The := constraint is different from the other constraints because it implies a logical relationship strong enough to bind a value. The other constraints will only compare values and result in an assessment of an existing bingding's validity.

Comparing Plural Values

Because plural values represent multiple possible values, saying they are 'equal' is not possible. However it can be said that they can resolve to an equal value, or that they are strictly less/greater than (:=, :<, and :>). In cases other than this many comparisions will result in :noanswer out of safety.

Comparing Integers

When comparing a variable to an integer (such as x < 4) and using comparision as a statement, resolution will result in a Guesswork.Constraint.Arithmetic.Range.

Summary

Types

constraint()

@type constraint() :: := | :<= | :< | :>= | :>

t()

@type t() :: %Guesswork.Constraint.Comparison{
  a: Guesswork.Ast.Variable.t() | Guesswork.Ast.Entity.t(),
  b: Guesswork.Ast.Variable.t() | Guesswork.Ast.Entity.t(),
  constraint: constraint(),
  negated: boolean()
}

Functions

apply(comparison)

@spec apply(t()) :: :ok | :error | :noanswer | Guesswork.Ast.Entity.t()

Applies a comparison constraint.

apply(a, constraint, b, negated)

@spec apply(
  Guesswork.Ast.Entity.t(),
  constraint(),
  Guesswork.Ast.Entity.t(),
  boolean()
) ::
  :ok | :error | :noanswer | Guesswork.Ast.Entity.t()

Applies a comparison constraint to the arguments.

negate_constraint(c, bool)

@spec negate_constraint(constraint(), boolean()) :: constraint() | :!=

new(a, constraint \\ :=, b, negated)

print(atom, bool)

@spec print(constraint(), boolean()) :: String.t()

reverse_constraint(c)

@spec reverse_constraint(constraint()) :: constraint()