Example of list processing


next up previous contents
Next: Another example of list processing
Up: Introduction to Prolog for Mathematicians
Previous: Example of structure-processing: complex numbers.

Example of list processing

member( X, [X|Tail] ).

member( X, [Head|Tail] ) :-
    member( X, Tail ).

Read this as:

X is a member of any list whose
first element is X.

X is a member of any list if
    X is a member of the tail of
    the list.

Standard terminology in list processing: The head of a list is its first element. The tail of a list is the sublist formed by its second, third, ... elements.



Jocelyn Ireson-Ireson-Paine
Mon Jul 17 22:27:41 BST 1995