在 SWI

编程入门 行业动态 更新时间:2024-10-26 17:25:28
本文介绍了在 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

本文发布于:2023-11-29 22:09:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647770.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SWI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!