List Prolog SWI列表创建

List Prolog SWI列表创建,list,prolog,List,Prolog,知识表示: student('John','f214','A'). student('John','f222','B'). student('John','f213','C'). student('John','f343','D'). subject(f214,3). subject(f222,3). subject(f213,3). subject(f343,3). 根据Prolog SWI中给定的知识表示,我如何创建课程列表[f214、f222、f213、f343]和相应等级列表['A'

知识表示:

student('John','f214','A').
student('John','f222','B').
student('John','f213','C').
student('John','f343','D').

subject(f214,3).
subject(f222,3).
subject(f213,3).
subject(f343,3).

根据Prolog SWI中给定的知识表示,我如何创建课程列表[f214、f222、f213、f343]和相应等级列表['A'、'B'、'C'、'D']

您可以使用
findall/3

?- findall(Course, subject(Course, _), Courses).
Courses = [f214, f222, f213, f343].

?- findall(Grade, student(_,Grade,_), Grades).
Grades = [f214, f222, f213, f343].

?- findall(course_grade(Course, Grade), (subject(Course,_), student(_,Course,Grade)), CoursesGrades).
CoursesGrades = [course_grade(f214, 'A'), course_grade(f222, 'B'), course_grade(f213, 'C'), course_grade(f343, 'D')].

我不明白一门课程是如何分配一个年级的,这是不是像参加该课程的学生的平均成绩那样的某种聚合?