我正在Prolog中对这段代码进行一些查询:
student(ali).
student(sami).
student(rami).
student(mousa).
student(muna).
student(amal).
student(omar).
course(ai).
course(java).
course(calculus2).
course(calculus1).
course(robots).
teacher(hashem).
teacher(mohammad).
teacher(ibrahim).
teacher(kareem).
prerequest(ai,java).
prerequest(calculus2,calculus1).
prerequest(robots,ai).
study(ali,ai).
study(ali,java).
study(sami,java).
study(rami,calculus2).
study(mousa,ai).
study(muna,java).
study(amal,calculus1).
study(omar,robots).
teach(hashem,ai).
teach(mohammad,java).
teach(ibrahim,calculus2).
teach(ibrahim,calculus1).
teach(kareem,robots).
teacher_of(X, Y):-
study(X, Z),
teach(Z, Y).
现在,我想找到所有老师的学生“阿里”吗?我以前试过这样做:
?- teacher_of(ali, B).
但是它给了我一个错误,以及消息末尾的一个假单词(作为答案)。
注意:我正在使用这个在线编辑器:这里。
你有什么建议吗?
提前谢谢。
发布于 2018-03-21 22:03:30
你必须写:
teacher_of(X,Y):-
study(X,Z),
teach(Y,Z).
?- teacher_of(ali, B).
B = hashem
B = mohammad
(你交换了Z
和Y
在teach/2
。要找到所有的老师,只需使用findall/3
?- findall(B,teacher_of(ali, B),LB)
LB = [hashem, mohammad]
https://stackoverflow.com/questions/49416911
复制相似问题