Tutorial by Examples

Lists are a special kind of compound term. Lists are defined inductively: the atom [] is a list, denoting the empty list. if Ls is a list, then the term '.'(L, Ls) is also a list. There is a special syntax for denoting lists conveniently in Prolog: The list '.'(a, '.'(b, '.'(c, []))) can a...
By convention, the functor (-)/2 is often used to denote pairs of elements in Prolog. For example, the term -(A, B) denotes the pair of elements A and B. In Prolog, (-)/2 is defined as an infix operator. Therefore, the term can be written equivalently as A-B. Many commonly available predicates also...
In all serious Prolog systems, association lists are available to allow faster than linear access to a collection of elements. These association lists are typically based on balanced trees like AVL trees. There is a public domain library called library(assoc) that ships with many Prolog systems and ...
On a very high level, Prolog only has a single data type, called term. In Prolog, all data is represented by Prolog terms. Terms are defined inductively: an atom is a term. Examples of atoms are: x, test and 'quotes and space'. a variable is a term. Variables start with an uppercase letter or un...
The [record][1] library provides the ability to create compound terms with named fields. The directive :- record/1 <spec> compiles to a collection of predicates that initialize, set and get fields in the term defined by <spec>. For example, we can define a point data structure with nam...

Page 1 of 1