This predicate causes an expression to be evaluated and a value to be unified with a term.
is/2
'is'(Result, Expression)
is true iff the value of evaluating Expression
as an expression is Result
.
Templates and modes for the predicate are as follows:
is(?term, @evaluable)
Note that is
is a predefined operator.
Let's start with some simple tests verifying success or failure of single goals.
alice.tuprolog.SimpleGoalFixture | |
goal | success() |
'is'(3, 3). | true |
'is'(3, 3.0). | false |
'is'(foo, 77). | false |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
fit.ActionFixture | |
start | alice.tuprolog.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
fit.ActionFixture | ||
enter | query | 'is'(Result, 3 + 11.0). |
check | hasSolution | true |
enter | variable | Result |
check | binding | 14.0 |
enter | query | X = 1 + 2, Y is X * 3. |
check | hasSolution | true |
enter | variable | X |
check | binding | 1 + 2 |
enter | variable | Y |
check | binding | 9 |
The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.
alice.tuprolog.PrologActionFixture | ||
enter | query | 'is'(77, N). |
check | hasSolution | false |
check | exception | instantiation_error |
Run the tests!
The results of the tests for Arithmetic evaluation are as follows:
fit.Summary |