如何在序言中打印所有数据库事实 [英] how can I print all database facts in prolog
本文介绍了如何在序言中打印所有数据库事实的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 prolog 中有一个数据库,我要做的就是枚举它的元素并一一打印.如何做到这一点?
I have a database in prolog, all I want to do is enuamrate through its element and print one by one. How can this be done?
fact(is(mike,asthmatic)).
fact(has(andy,highPressure)).
fact(is(mike,smoker)).
我写了这个,它工作正常,但它从数据库中删除元素,所以我想访问它们而不删除.
I have written this, which works ok but it removes elements from the database, so I want to access them without removing.
print:-
retract(factA(P)),
write(factA(P)),nl,
fail.
print.
推荐答案
你也可以考虑使用 forall/2
谓词:
You might also consider using forall/2
predicate:
print:-
forall(fact(P), writeln(P)).
这篇关于如何在序言中打印所有数据库事实的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文