私は SICStus Prolog を使用しており、一連の事実があります。
student('John Henry', 'Maths').
student('Jim Henry', 'Maths').
student('John Alan', 'Maths').
student('Alan Smith', 'Computing').
student('Gary Henry', 'Maths').
両方の学生が異なる2人の学生の共有科目を取得したいので、次のようになりました。
sharedSubject(S1, S2, Sub) :- S1 \== S2, student(S1, Sub), student(S2, Sub).
ただし、入力すると:
sharedSubject('John Henry', F, E).
私は得るF = 'John Henry'
。誰かが私が間違っている場所と何をする必要があるかを指摘できますか? ありがとう。