私はPrologを学んでいて、次の行があります。
Consider the following Prolog program. It contains facts regarding instructors of classes and
in which classes students are enrolled. instructor(p,c) means that professor p is the instructor
of course c. enrolled(s, c) means that student s is enrolled in course c. We want to use these
facts to answer queries concerning the professors who teach particular students.
instructor(fibonacci, math100).
instructor(turing, cs330).
instructor(galileo, phys210).
enrolled(john, math100).
enrolled(sofia, cs330).
enrolled(ryan, phys210).
enrolled(lisa, math100).
enrolled(matt, cs330).
enrolled(lisa, cs330).
そして、質問があります:
What would Prolog return given the following queries? If a query has more than one answer, list all the answers.
?- instructor(galileo, _).
?- instructor(_, ee100).
私は他のすべての問題を終えましたが、理解に問題があります'_'
。Prologはどのような答えを出しますか?以下のために?- instructor(galileo, _).
私の仮定であるphys210
が、何秒約1?
「何が起こるか」の通常の答えは「試してみてください」です。_
プロローグの「ドントケア」であり、匿名で何とでも統合されます。それで、あなたの最初のクエリ:
?- instructor(galileo, _).
で成功しtrue
ます。それをクエリと比較してください:
?- instructor(galileo, X).
これは成功し、実際X
にphys210
。と統合されます。
instructor
2番目の引数がee100
。である句がないため、2番目の目標は失敗します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加