Home » Types of Prolog

Types of Prolog

Prolog is used to provide the Tuples, lists, numbers, atoms, and patterns. In this section, we can define the type of objects that are passed as arguments.

Simple Types

This type of Prolog is implementation-dependent. The following table shows the implementation of a simple type of prolog:

TYPE VALUES
Boolean true, fail
Variables variables
Integer integers
Atom character sequence
Real floating point number

The Boolean constants are not passed as an argument. Variables describe the character string. The character strings start with a capital letter or upper case letter. Atoms are constants that have no numerical value. All the atoms start with a lower case letter or small letter.

Composition Types

The distinction between data and program are blurred in prolog. In the argument, data is often passed to predicates. In prolog, the most common data structure is lists. Lists are much like the stack in which we can only sequentially access the lists of elements, and much like the array in which we have a list of elements sequentially.

Prolog is used to allow arbitrary patterns as data, and that pattern represents tuples. An array is not provided by Prolog. But single or multidimensional arrays may be represented as a list or list of lists. The array can also be represented by a set of facts in the database.

TYPE REPRESENTATION [ comma separated sequence of items ] list pattern sequence of items

Using the square brackets ([]+), a prolog list can represent. The following example shows a list of fruits:

[mango, grapes, orange]

The above list shows the elements mango, grapes, and orange. In prolog list, the elements are ordered. If there are no indexes, the elements will also be ordered. Using the patterns, the tuples can be represented.

Example

book(author(aaby,anthony),title(labmanual),data(1991))

Using the pattern matching, the elements of tuples can be accessed.

book(Title,Author,Publisher,Date).author(LName,FName).

Type Predicates

The user has to determine the parameter type because prolog is a weakly typed language. To determine the parameter type in prolog, the following built-in predicate can be used.

PREDICATE CHECKS IF
atom(A) A is an atom
atomic(A) A is a number or an atom
number(N) N is an integer or real value
var(V) V is a variable
nonvar(NV) NV is not a variable
integer(I) I is an Integer
real(R) R is a floating-point number
T =L T is a term, L is a list
functor(T,F,A) T is a term with functor F, and A is an arity
clause(H, T) H :- T is a program rule

In the above example, T =..L, function(T,F,A), and clause(H,T) are used in program manipulation.

Here

clause(H,T): It checks the database content.
T =..L: It can manipulate terms.
functor(T,F,A): It can also manipulate terms.

The following example shows the predicate function:

functor (T,F,A)

T is a term, F is its functor, and A is its arity.

?- functor(t(x,y,z),F,A).
F = t
A = 6
yes

Here,

t: It is the function of the term
3: It is the arity of the term


Next TopicProlog Syntax

You may also like