I am writing a small interpreter in SWI Prolog and run into the following problem: I need to write a predicate that will determine if logical expression is true. I already have a predicate
evaluate_arithmetic_expression(+Expr, +State, -Value)
that evaluated arithmetic expression in a given state. Now I need a predicate for logical expressions:
is_logical_expression(+Expr, +State)
The following clause appears to work just fine:
is_logical_expression_true(Expr1 = Expr2, State) :-
evaluate_arithmetic_expression(Expr1, State, Value1),
evaluate_arithmetic_expression(Expr2, State, Value2),
Value1 =:= Value2.
But this won't compile:
is_logical_expression_true(Expr1 <> Expr2, State) :-
evaluate_arithmetic_expression(Expr1, State, Value1),
evaluate_arithmetic_expression(Expr2, State, Value2),
Value1 =\= Value2.
And I get error:
Syntax error: Operator expected
It looks like <>
operator binds harder than anything else, but I don't think <>
is even an operator in SWI. How can I fix this?
User-defined operators must be declared by using the ISO predicate op/3:
:- op(700, xfx, (<>)).