"underscore" 应该用什么值代替?
What value should be instead of "underscore"?
我正在学习 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
但是第二个呢?
'what will happen' 的通常答案是 'try it'。 _
是序言的"don't care",它会匿名统一任何东西。这样,您的第一个查询:
?- instructor(galileo, _).
会成功,true
。将其与查询进行比较:
?- instructor(galileo, X).
它成功了,并且确实统一了 X
和 phys210
。
你的第二个目标失败了,因为没有子句 instructor
其中第二个参数是 ee100
.
我正在学习 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
但是第二个呢?
'what will happen' 的通常答案是 'try it'。 _
是序言的"don't care",它会匿名统一任何东西。这样,您的第一个查询:
?- instructor(galileo, _).
会成功,true
。将其与查询进行比较:
?- instructor(galileo, X).
它成功了,并且确实统一了 X
和 phys210
。
你的第二个目标失败了,因为没有子句 instructor
其中第二个参数是 ee100
.