在 SWI-Prolog 中获得多种解决方案 [英] Get multiple solutions in SWI-Prolog

查看:40
本文介绍了在 SWI-Prolog 中获得多种解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 SWI-Prolog 的初学者(但对 Borland Prolog 有一些经验),我遇到了以下测试代码的奇怪行为:

I'm beginner in SWI-Prolog (but have some experience in Borland Prolog), and I've faced with a strange behavior for the following test code:

test(10).
test(1).

期望查询 ?-test(A) 得到 2 个解,比如 A = 10;A = 1.但是,仅生成 A = 10.我不使用这里的切口.也许在 SWI-Prolog 中默认关闭回溯?

It is expected for query ?-test(A) to get 2 solutions, something like A = 10; A = 1. However, only A = 10 is produced. I don't use the cut here. Maybe backtracking is off by default in SWI-Prolog?

提前致谢

推荐答案

抱歉,答案很简单(参见 SWI-Prolog 文档):

Sorry, the answer is very simple (see SWI-Prolog doc):

用户可以输入分号 (;) 或空格键,如果他想要其他解决方案.如果您不想看到更多答案,请使用返回键.如果用户使用返回键或 Prolog 知道没有更多答案,Prolog 会以句号 (.) 完成输出.如果 Prolog 找不到(更多)答案,它会写为 false.

The user can type the semi-colon (;) or spacebar, if (s)he wants another solution. Use the return key if you do not want to see the more answers. Prolog completes the output with a full stop (.) if the user uses the return key or Prolog knows there are no more answers. If Prolog cannot find (more) answers, it writes false.

这篇关于在 SWI-Prolog 中获得多种解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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