goldking123
Instructor
i have made knowledge base in prolog for a student. whose roll no, is 01, i have entered the courses taken by him, year,session,and grade. now i want to create a list of all the courses taken along waith the year and grade. i made following algo. but it didnt work. please help.
coursetaken(01,mt410,15,fall,'c').
coursetaken(01,mt411,15,fall,'b').
coursetaken(01,mt412,15,fall,'a').
coursetaken(01,mt413,15,fall,'c').
coursetaken(01,mt414,15,fall,'a').
coursetaken(01,mt415,15,fall,'a').
coursetaken(01,mt416,15,fall,'a').
coursetaken(01,mt417,15,fall,'a').
coursetaken(01,mt418,15,fall,'a').
coursetaken(01,mt419,15,fall,'a').
coursetaken(01,mt420,15,fall,'a').
coursetaken(01,mt421,15,fall,'a').
coursetaken(01,mt422,15,fall,'a').
coursetaken(01,mt423,15,fall,'a').
coursetaken(01,mt424,15,fall,'a').
coursetaken(01,mt425,15,fall,'a').
list_courses(Sid,L):-list_courses(Sid,[],L).
list_courses(Sid,Acc,L):-coursetaken(Sid,Cno,_,_,_),\+member(Cno,Acc),
append([Cno],Acc,L1), list_courses(Sid,L1,L),!.
list_courses(_,Acc,Acc).
coursetaken(01,mt410,15,fall,'c').
coursetaken(01,mt411,15,fall,'b').
coursetaken(01,mt412,15,fall,'a').
coursetaken(01,mt413,15,fall,'c').
coursetaken(01,mt414,15,fall,'a').
coursetaken(01,mt415,15,fall,'a').
coursetaken(01,mt416,15,fall,'a').
coursetaken(01,mt417,15,fall,'a').
coursetaken(01,mt418,15,fall,'a').
coursetaken(01,mt419,15,fall,'a').
coursetaken(01,mt420,15,fall,'a').
coursetaken(01,mt421,15,fall,'a').
coursetaken(01,mt422,15,fall,'a').
coursetaken(01,mt423,15,fall,'a').
coursetaken(01,mt424,15,fall,'a').
coursetaken(01,mt425,15,fall,'a').
list_courses(Sid,L):-list_courses(Sid,[],L).
list_courses(Sid,Acc,L):-coursetaken(Sid,Cno,_,_,_),\+member(Cno,Acc),
append([Cno],Acc,L1), list_courses(Sid,L1,L),!.
list_courses(_,Acc,Acc).