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
@type constraint() :: := | :<= | :< | :>= | :>
@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
@spec apply(t()) :: :ok | :error | :noanswer | Guesswork.Ast.Entity.t()
Applies a comparison constraint.
@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.
@spec negate_constraint(constraint(), boolean()) :: constraint() | :!=
@spec new( Guesswork.Ast.Variable.t() | Guesswork.Ast.Entity.t(), constraint(), Guesswork.Ast.Variable.t() | Guesswork.Ast.Entity.t(), boolean() ) :: t()
@spec print(constraint(), boolean()) :: String.t()
@spec reverse_constraint(constraint()) :: constraint()