如何通过 shell 调用在 SWI-Prolog 中显示模式匹配目标的结果? [英] How do I show the results of pattern-matching goals in SWI-Prolog from a shell invocation?

查看:42
本文介绍了如何通过 shell 调用在 SWI-Prolog 中显示模式匹配目标的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道从 shell 调用时如何从 SWI-Prolog 获取输出.

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

假设我有一个简单的知识库,kb.pl:

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

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

我可以从 shell 调用 SWI-Prolog:

I can invoke SWI-Prolog from the shell:

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

并将我的知识库列表打印到 stdout.如果我试试这个:

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

表明 Prolog 正确地未能找到匹配的事实.

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

我的问题是:如何打印所有匹配项,以便从 shell 看到输出,就像我在 Prolog 环境中一样?例如

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.

我不认为 --quiet 是问题所在.它只是抑制 prolog 启动消息.见 SWI-Prolog 命令行选项

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

推荐答案

自己打印,例如:

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

这篇关于如何通过 shell 调用在 SWI-Prolog 中显示模式匹配目标的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆