Search code examples
prologanswer-set-programming

How can I go through a list of facts in Answer Set Prolog?


I have a list of facts like

student(mary).
student(john).

etc, and also

course(math).
course(a).
course(b).

etc, and

took(john,math).
...

I have to say if a student can or can not graduate.

To graduate a student have to have all the courses taken. But how can I say this without write all term in the rule?

what I think was

can_graduate(X) :- took_all_courses(X). 

but I dont know how to explain the rule took all courses without writing all courses. Can someone help me?

thanks.


Solution

  • took_all_courses(Student) :-
      student(Student),
      forall( course(C), took(Student,C) ).