a challenging list question on prolog
I am ne开发者_如何学运维w on prolog. Can you help me to solve this problem, please.
exam(math, paul).
exam(phys, paul).
exam(cmpe, sofia).
exam(bio, george).
I want to implement the predicate otherExam(L, N). L is a lesson, and N is the list of all lessons (except L) haved by student of L.
otherExam(math,X). returns [phys]
otherExam(cmpe,X). returns []
otherExam(chem,X). returns false (no such lesson)
otherExam(math,[phys]) returns true
otherExam(X,[phys]). returns math
I haved stucked with this problem. If you help me, I will be very happy :))
check findall/3 and select/3
findall/3 is used to get all the possible results from a query
for example, findall(X,ancestor(X,paul),L) will find all X such as X is an ancestor of paul and will put them in the list L
精彩评论