How to echo the true/false value Prolog returns after a query

对着背影说爱祢 提交于 2019-12-24 20:04:42

问题


I 'd like to pose a question. I tried to connect php with SWI-Prolog using the exec function and my effort was succeful. I have managed to query prolog via php and I was able to echo Prolog's answer.

What I want to do but can't figure how to accomplish it, is to echo the true/false prolog returns.

Lets assume I have a simple knowledge_base.pl file with these facts and rules:


girl(erin).
boy(john).
likes(erin,reading).
likes(john,reading).
hangs_out_with(erin,X) :- likes(X,reading), boy(X), writeln('Someone s got a new friend!!').

Given the simple knowledge base above one can pose queries and prolog respond.

for example:

?- girl(erin). Prolog based on our knowledge base will respond true.
?- girl(john). Prolog based on our knowledge base will respond false.
?- hangs_out_with(erin,john). Proslog will respond : Someone s got a new friend!! true.

What I need is for PHP to echo the true or false respond. How can I achieve that?

Thanks in advance for you help.

来源:https://stackoverflow.com/questions/12428012/how-to-echo-the-true-false-value-prolog-returns-after-a-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!