How do I show the results of pattern-matching goal

2019-05-23 15:30发布

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条回答
看我几分像从前
2楼-- · 2019-05-23 15:59

Print it yourself, for example with:

$ swipl -q -s kb.pl -t "dad(elvis,X), writeln(X), false"
查看更多
登录 后发表回答