Skip to main content
. 2005 Aug 5;6:198. doi: 10.1186/1471-2105-6-198

Table 1.

PROLOG rules, syntax and semantic, example

% X belongs to a list if X is at the start of the list
Element(X, [X|_]).
% or X belongs to a list if the list starts with Y different from X but X belongs to the list 's queue
Element(X, [Y|;L]) :- different(X, Y), element(X, L).
a user of a such program asks it like this: Answer
>element(9, [5, 3, 4, 7]. answer = fail
>element(3, [5, 3, 4, 7]. answer = ok
>element(X, [5, 3, 4, 7]. answer = ok, X = 5 or X = 3 or X = 4 or X = 7

a(X, Y) :- b(X), c, d(X, Y) can be read like this: a is true for X and Y values if b is true for X value, c is true and d is true for X and Y value. Here is a very short example to explain how works a PROLOG program. Suppose we want to write a program able to verify that an element belongs to a list or able to enumerate list's elements. In PROLOG we just have to describe "belonging" concepts.