Episteme.Builtins.Arithmetic (Episteme v0.1.0)

Copy Markdown View Source

Evaluates a Prolog arithmetic expression term to an Elixir number under bindings -- is/2's own right-hand side, and both sides of every arithmetic comparison (numeric_equal/2, </2, ...). Raises (via Episteme.Builtins.Exceptions.prolog_throw/1) a standard type_error for anything that isn't a number, a bound variable, or a recognized evaluable functor.

Also dispatch/3, wired into Episteme.Engine's builtin-dispatch chain the same way Episteme.Builtins.Lists/Episteme.Builtins.Io are: between/3, the one integer-generating goal in this family (everything else here is a plain expression evaluator, not a backtracking goal).

Summary

Functions

is/2, numeric_equal/2, </2 and friends share this: evaluate both sides then apply cmp.

Functions

compare(a, b, bindings, cmp)

@spec compare(term(), term(), Ichor.Backtrack.Bindings.t(), (number(), number() ->
                                                         boolean())) ::
  boolean()

is/2, numeric_equal/2, </2 and friends share this: evaluate both sides then apply cmp.

dispatch(arg1, arg2, arg3)

@spec dispatch(atom(), non_neg_integer(), [term()]) ::
  Ichor.Backtrack.goal() | :not_handled

eval(expr, bindings)

@spec eval(term(), Ichor.Backtrack.Bindings.t()) :: number()