遵循以下规则:
test('John', ebola).
test('John', covid).
test('Maria', covid).
我该如何创建一个谓词来告诉我约翰或玛丽亚是否参加了埃博拉和Covid考试?
我想做类似的事情(我知道这是错误的,只是想法):
tests(Persona, Ebola, Covid) :-
Ebola = test(Persona, ebola),
Covid = test(Persona, covid).
Prolog是关系不起作用的。test(X,Y)保持或失败,并且不返回您所想的值。这是您应该写的:
tests(Persona) :-
test(Persona, ebola),
test(Persona, covid).
您可以查询tests('John'),这是正确的,因为两个test / 2调用均成功。查询test('Maria')失败,因为test('Maria',ebola)失败。
它能回答您的问题吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句