How do I show the results of pattern-matching goals in SWI-Prolog from a shell invocation?

眉间皱痕 提交于 2019-12-22 12:38:36

问题


I am wondering how one gets output from SWI-Prolog when invoking it from the shell.

Say I have a simple knowledge base, kb.pl:

dad(elvis, lisaMarie).
dad(john, julian).

I can invoke SWI-Prolog from the shell:

$ swipl --quiet -s kb.pl -t listing

and a listing of my knowledge base is printed to stdout. If I try this:

$ swipl --quiet -s kb.pl -t "dad(elvis, X)"
$ echo $?
0

No output is printed, but I know that it found matches because I get zero when I then query for the return code. Similarly:

$ swipl --quiet -s kb.pl -t "dad(morrisey, X)"
$ echo $?
1

Shows that that the Prolog is correctly failing to find a matching fact.

My question is this: How do I get all the matches to print, so that from the shell I can see output like when I am in the Prolog environment? E.g.

$ swipl --quiet -s kb.pl -t "dad(elvis,X)" --magicdust
X = lisaMarie.

I don't think --quiet is the problem. It is just suppressing prolog startup messages. See SWI-Prolog Command-Line Options


回答1:


Print it yourself, for example with:

$ swipl -q -s kb.pl -t "dad(elvis,X), writeln(X), false"


来源:https://stackoverflow.com/questions/11234469/how-do-i-show-the-results-of-pattern-matching-goals-in-swi-prolog-from-a-shell-i

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