应该用什么价值而不是“下划线”?

时间:2015-10-15 00:09:49

标签: prolog logic

我正在学习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 个答案:

答案 0 :(得分:1)

“将会发生什么”的常见答案是“试一试”。 _是prolog的“不关心”,它将匿名地与任何东西统一。这样,您的第一个查询:

?- instructor(galileo, _).

将成功,true。将其与查询进行比较:

?- instructor(galileo, X).

成功,并确实将Xphys210统一起来。

你的第二个目标失败,因为没有第instructor条,其中第二个参数是ee100