Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program and Data are the Same in Prolog?

Tags:

prolog

I have heard that in Prolog, program and data are the same thing. What does that mean?

like image 550
Yugga Avatar asked Mar 02 '10 01:03

Yugga


1 Answers

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.

like image 90
Enigmativity Avatar answered Sep 28 '22 04:09

Enigmativity