... term[*]
A term is
  1. a constant
  2. a variable
  3. a structure, consisting of a functor (which is a constant) followed by a sequence of terms enclosed in brackets and separated from one another by commas.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
...grandmother/2.[*]
Note the standard conventional way of citing a Prolog predicate in the form predicate_name/arity.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
... programming.[*]
For those of you who know about these things: Prolog does not contain 'while' loops, so recursion replaces loops.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
... argument:[*]
The first/2 predicate could just as well have been defined as follows, with explicit calls to the unification operator =/2: first(List, First):- List = [HeadTail], First = Head. The version in the text has moved these calls from the body of the definition into the head of the definition (as a result of which the body is empty). This technique is called 'unfolding' and is a commonly used technique in Prolog programming.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
... 'no'.[*]
This definition of member/2 can be simplified slightly by 'unfolding' the call to =/2 and placing it in the head of the rule, to give: member(Item, [ItemList]). member(Item, [_Tail]):- member(Item, Tail).
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
... Expression[*]
Remember that the equals sign is used in Prolog for unification, not arithmetic.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
... list:[*]
length/2 comes predefined in SICStus Prolog. If you put this definition in a file and consult it, you will receive an error message. The solution is to rename the predicate in your definition, e.g. to mylength/2.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.