- ... term
![[*]](file:/sw/lib/latex2html/icons/footnote.png)
- A term is
- a constant
- a variable
- 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.
![[*]](file:/sw/lib/latex2html/icons/footnote.png)
- Note the standard conventional way of
citing a Prolog predicate in the form predicate_name/arity.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ... programming.
![[*]](file:/sw/lib/latex2html/icons/footnote.png)
- For those of you who know about
these things: Prolog does not contain 'while' loops, so recursion
replaces loops.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ... argument:
![[*]](file:/sw/lib/latex2html/icons/footnote.png)
- 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'.
![[*]](file:/sw/lib/latex2html/icons/footnote.png)
- 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
![[*]](file:/sw/lib/latex2html/icons/footnote.png)
- Remember that the equals sign is used
in Prolog for unification, not arithmetic.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
- ... list:
![[*]](file:/sw/lib/latex2html/icons/footnote.png)
- 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.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.