1.1 ANTECEDENTE HISTÓRICO
4. Cuando exista necesidad objetivamente acreditada de amortizar puestos
Prolog’s domain of inference is the domain of terms. A term is defined by its type: it may be anatom, avariable, anumber, apredicate, astructureor alist:
• anatom is given as any sequence of characters starting with a lower case letter, or starting with lower or upper case letter but put between dou- ble or single quotes3. Atoms are non-numerical (i.e. logical or symbolic) constants. E.g. blu_skyis a logical constant, because in a given situa- tion it may be true or false, and "Antoni Niederlinski"is a symbolic constant because no logical value can be assigned to it. The use of quotes distinguishes atoms that start with upper case letters from variables;
• avariable given as any sequence of characters starting with an upper case letter or underscore, e.g. X, A, John, Who, _who, _how_much. Variables inProlog andCLP are used asunknowns, similar as in logic and algebra. This is contrasted with variables in procedural programs, where they are place-holders for varying but known entities. A discussion of modes of variables is presented in Section 2.1.3. A single underscore (_)denotes ananonymous variable and means ”any term”; it is used to preserve the defined predicate arity in case the value of the variable occupying the place of the anonymous variable is of no interest;
• anumberis given as any integer constant (like-10,-6,0,2,8) or floating- point constant (like 2.71, 3.14) with decimal points only4;
3Single (straight) quotes will be avoided in programs discussed in this book. This is so
because they are converted in text files (e.g. PDF files) into lexicographic (curly) quotes that are not recognized byECLiP Se. So a scan of a PDF-file program with such quotes cannot be activated.
• apredicate is arelation between variables, e.g. likes(Somebody, Something),
where likes is the predicate name (always starting with a lower case letter), while(Somebody, Something)is atuple i.e. anordered sequence of the predicate arguments. The number of arguments is referred to as arity of predicate, to be used in references likename/arity(likes/2 in our example). For the relation to be meaningful, sets (or inCLP-parlance: domains) for both variables have to be defined: e.g. the variableSomebody may take values from the set of names of 20 students attending my lecture, and the variableSomething may take values from the set of names of5 popular programming languages.
The above predicate is a formalized prefix version of the colloquial infix sentence
"Somebody likes Something";
the predicate prefix form, although awkward for colloquial use, has the undeniable advantage of providing easy access to the subject (Somebody), object (Something) and predicate (likes) of the sentence. What’s more, the prefix form can easily accommodate a large number of arguments. Having defined the predicate arguments as variablesSomebodyandSome- thing, a predicate as such has no logical value: it is neither true nor false, but ambiguous. However, it forms a blueprint for a grounded predicate, with variables bounded to some constants, e.g.
likes("John Smith","Prolog and CLP")
that may be either a false (unsatisfied) statement or a true (satisfied) state- ment for some particular"John Smith"from my group of 20 students5. It should be stressed that predicate arguments form a tuple, i.e. their order matters; it must be the same for any usage of the predicate. This is so becauseProlog andCLP identify variables across clauses not by their names, but by their position in the tuple. Thus
likes("John Smith","Prolog and CLP") and
likes("Prolog and CLP","John Smith"),
should not appear in the same program, although they may mean (from the programmers point of view) exactly the same thing.
Predicates may benested: any predicate may serve as argument of another 5Because any bounding of the predicate arguments to some constants produces aproposi-
predicate, e.g.:
likes(graduate_student(Somebody),
computer_science_subject(Something)).
A special case of predicates are functions6: all functions are predicates, but not all predicates are functions. Therefore no distinction will further be made between them. Because for some functions infix notation with standard operators is normally used (e.g. X1 + X2, where"+"is the stan- dard operator), such infix notation is also accepted byProlog andCLP. Predicates may be divided into:
1. Standard predicates (built-in predicates), defined and designed by Prolog or CLP language designers, and made available to users. They are farther divided into elementary predicates, defining basic relations as given in librariesicand branch_and_bound, with argu- ments contained at most in one list, and global predicates, defining advanced relations as given in librariesic_global,ic_cumulative, ic_edge_finder, ic_edge_finder3, with arguments usually con- tained in manylists.
2. Private predicates, defined and designed byProlog orCLP program designers, with names different from those of standard predicates, and with arbitrary number of lists.
• a structure is presenting a tuple of a fixed number of atoms, called its arguments. Any structure has a name (which looks like an atom). The number of arguments of a structure is called its arity. The name and arity of a structure are together called itsfunctor and is often written as name/arity. Functors could be seen as general data types, arguments as defining instances of those data types. Structures correspond to records in other languages. Although structures look deceivably like predicates, they differ from them because they do not contain variables; therefore are always true.
• alist of terms, including an empty list. A (nonempty) list may look like: [a, b, "CDE", 5, F], an empty list is denoted by []. For details see Section 2.1.8.
6For a set of n variables with declared domains, a function is declaring - for some subset of
values ofn-1variables (called arguments) a unique value of the n-th variable, called (called outputs)