Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Syntax error: Operator expected in Prolog

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

User-defined operators must be declared by using the ISO predicate op/3:

:- op(700, xfx, (<>)).
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading