tags:

views:

115

answers:

4

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

+5  A: 

It means that your program is implemented as a bunch of rules, and data is also implemented as a bunch of rules - there's no distinction between a rule that causes some operations to happen (a program), and a rule that just gives back a data value.

Carl Norum
+1  A: 

This refers to terms being data, but the program also being described in terms.

Tronic
A: 
 ?- A=write(B), C=(B is 1+2), Prog = (C, A).
A = write(B),
C = (B is 1+2),
Prog = (B is 1+2, write(B)).

 ?- $Prog.
3
true.
Xonix
+3  A: 

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.

Enigmativity
Thanks. Excellent answer.
John Saunders