I have heard that in Prolog, program and data are the same thing. What does that mean?
Prolog source is just a list of rules. Some rules are just "data" - they are true
without further evaluation.
person(james).
father(james, thomas).
"James is a person." "James is the father of thomas."
These rules are the data.
I can run a query against this data. I can ask:
?- person(X).
The answer will be:
X = james.
Or:
?- father(X, thomas).
The answer will be the same.
Other rules need further evaluation.
grandfather(X, Z) :- father(X, Y), father(Y, Z).
This is a simple "program".
Our grandfather program will evaluate to true if we have the right data. For example:
father(james, william).
father(james, tyler).
father(james, thomas).
father(jeff, james).
If I execute the following program:
?- grandfather(jeff, X).
I get:
X = william
I can ask prolog to continue and I will get X = tyler
and X = thomas
.
The syntax gets more complicated, but the basics are the same. The data and the program are just a set of facts. The art of prolog is making the right rules that drive the computation to a result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With