The structure of the facts is
%structure
student(ID,FirstName,LastName,[courseList]).
course(CourseCode,CourseTtile,Credits,Level).
Following is the fact.
student(20135639,'Mohammed','Abdul Wahab',
[course('ITIS411','DATABASE SYSTEM IMPLEMENTATION',3,hard),
course('ITIS412','INFORMATION SECURITY',3 ,easy),
course('ITIS499','SENIOR PROJECT',3,hard),
course('ITIS469','AI',3,hard)] ).
I want to write a rule that sums the credits hours from the list
sum([],0).
sum(H|T,S):-
sum(T,S1),
S is H + S1.
sumCr(Id, Cr):-
student(Id,_,_,Courselist),
sum(Courselist,Cr).
The above rule sums all the elements of the facts in the list but I want to sum only the Cr value of all facts in the list. So when i run the following query, the output should be.
?. sumCr(20135639, Cr).
Cr=12.