lists.pl 641 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
% list e.g. [1,2,3] or [jamie,cersei], empty list = []
% pattern matching with lists:
% [Head|Tail], where Head is an element and Tail is a List!
%
%TODO:
% append(List,List2,Result).


append([],List2,List2).
append([Head|Tail],List2,[Head|Result]):-
	append(Tail,List2,Result).


% numbers and if clauses in Prolog, the Paranthesis are important!
dead_person(joanna).
dead_person(motherOfjohn).

%count_dead_persons(List,NumberOfPersonsInListThatAreDead)
count_dead_persons([],0).
count_dead_persons([Head|Tail],Number):-
	count_dead_persons(Tail,OldNumber),
	(
		dead_person(Head) ->
		Number is OldNumber + 1;
		Number = OldNumber
	).