Next:
Prolog Lispism
Up:
prolog
Previous:
Arithmetic Examples
Lists in Prolog
Elements of lists are any valid Prolog data object
Elements are terms separated by commas, do not have to be same type
Vertical bar separates head (first) from tail (rest)
The head of [john, mary, pat] is john
The tail of [john, mary, pat] is [mary, pat]
The representation of the combination is Head | Tail (in our example, [john | [mary, pat]] or [john | [mary | [pat | []]]])
Member function
member(X, L) :- L = [X|_]. member(X, L) :- L = [A|B], member(X,B).