知识表示:
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’
发布于 2013-11-25 05:57:11
您可以使用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')].https://stackoverflow.com/questions/20181228
复制相似问题