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

Why is this code in PROLOG giving me a syntax error?

col_tri(Vars):- Vars=[X1,X2,X3],
                Vars in 1..3,
                X1#\=X2,
                X1#\=X3,
                X2#\=X3,
                label(Vars).

This code is giving me this error in line 2 (Vars in 1..3,):
ERROR: c:/users/xxxx/desktop/prolog/tp2.pl:2:20: Syntax error: Operator expected

>Solution :

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

Operators are things like the + in 1 + 1, and in your code the in in Vars in 1..3.

Prolog code can define new operators at runtime.

The in operator is not a standard part of Prolog, it’s defined by the CLPFD library, which SWI Prolog has, but does not load automatically.

And in is for a single variable on the left, there is also ins for a list of variables like your Vars. So the code should become:

:- use_module(library(clpfd)).

col_tri(Vars):- Vars=[X1,X2,X3],
                Vars ins 1..3,
                X1#\=X2,
                X1#\=X3,
                X2#\=X3,
                label(Vars).
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