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

What does the 'line' predicate mean in Prolog?

I am currently trying to understand some Prolog code for a game, but I somehow can’t find any documentation about a specific predicate or rule that the programmer used, called ‘line’.

He uses it in the argument list of other predicates, but neither is it customly defined by him nor can I find it in any documentation or anywhere else on the internet. I can’t even call it seperately in my Prolog interpreter, even though it works perfectly in his code.

Can anyone tell me, what this predicate means or does?

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

solve([line(_, Line, Constr)|Rest]) :-

(specifically the line(_, Line, Constr) part)

>Solution :

This isn’t a predicate, this is a data structure, in Prolog terminology, a compound term. Check out this glossary: https://www.swi-prolog.org/pldoc/man?section=glossary.

You probably have a list of lines, and each line is represented as a triple of values. Based on what you show it is a bit difficult to guess what exactly it contains. The _ in the first argument is the way the programmer says "I don’t care about this value".

A compound term is the only non-atomic data structure in Prolog. A list for example is a nested compound term like .(a, .(b, .(c, []))) but the language has built-in functionality to let you write this as [a, b, c].

You can think of compound terms, with their names and arity, as the typed objects of Prolog (but please don’t push this analogy too far).

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