I’m using: SWI-Prolog version 8.4.3 for x64-win64
i have a list of predicates :
ListP = [
patient(201, 4, 2, inTime),
patient(202, 3, 2, late),
patient(203, 2, 3, late),
patient(204, 1, 3, late),
patient(204, 1, 4, inTime),
patient(203, 2, 4, late),
patient(204, 1, 5, inTime),
patient(204, 1, 5, inTime)
].
and i want to count number of patients inTime categorized by their 3rd argument:
I want the result to be something like :
Occ = [
[patient(_, _, 2, inTime), 1],
[patient(_, _, 3, inTime), 0],
[patient(_, _, 4, inTime), 1],
[patient(_, _, 5, inTime), 2]
].
What i tried :
count_occurrences(List, Occ):-
findall(
[patient(_,_,X,inTime),L],
(bagof(true,member(patient(_,_,X,inTime),List),Xs), length(Xs,L)),
Occ
).
The result of my code :
Occ = [
[patient(_, _, 2, inTime), 1],
[patient(_, _, 4, inTime), 1],
[patient(_, _, 5, inTime), 2]
].
it works well except that it does not give me the result for the patient whose 3rd argument is 3
[patient(_, _, 3, inTime), 0]
is omitted.
Thanks for your help