Page 209 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 209
Unit 14: Prolog
14.4.4 Compound Term Notes
A compound term is composed of an atom called a functor and a number of “arguments”, which
are again terms. Compound terms are ordinarily written as a function followed by a comma-
separated list of argument terms, which is contained in parentheses. The number of arguments
is called the term’s arity. An atom can be regarded as a compound term with arity zero.
Example: Examples of compound terms are truck_year (‘Mazda’, 1986) and Person_Friends’
(zelda,[tom,jim]).
Compound terms with functors that are declared as operators can be written in prefix or infix
notation.
Example: The terms -(z), +(a,b) and =(X,Y) can also be written as -z, a + b and X = Y,
respectively.
Users can declare arbitrary functors as operators with different precedences to allow for
domain-specific notations. The notation f/n is commonly used to denote a term with function
f and arity n.
Special cases of compound terms:
Lists are defined inductively: The atom [] is a list. A compound term with functor . (dot)
and arity 2, whose second argument is a list, is itself a list. There exists special syntax for
denoting lists: .(A, B) is equivalent to [A|B].
Strings: A sequence of characters surrounded by quotes is equivalent to a list of (numeric)
character codes, generally in the local character encoding or Unicode if the system supports
Unicode.
Task Make distinction between numbers, atoms and variables.
Self Assessment
Fill in the blanks:
6. ...................... is composed of a sequence of characters that is parsed by the Prolog reader as
a single unit.
7. A ...................... is composed of an atom called a functor and a number of “arguments”,
which are again terms.
14.5 Control Structures
14.5.1 Conjunction, Disjunction, Fail and True
As in practically all Prologs, the comma (,) means “and,” the semicolon (;) means “or,” fail
always fails, and true always succeeds with no other action.
LOVELY PROFESSIONAL UNIVERSITY 203