问题标签 [iso-prolog]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2276 浏览

prolog - GNU Prolog 断言错误

我是 Prolog 的新手,但我被这个所谓的简单命令所困扰。我已经加载了一个没有错误的知识库,每当我尝试断言(甚至帮助)时,我都会收到以下消息:

我到底错过了什么?赞赏。

0 投票
3 回答
1268 浏览

prolog - Swi prolog 错误:显示真但不假

刚刚在我的 W8 机器上安装了 SWI-Prolog,它抛出了一个错误。

这是错误:

假设我的 prolog 源文件包含一个事实:

所以我编译缓冲区,并得到:

现在当我输入

预期的输出是true。但是,当我输入说,

我收到上面发布的错误,而不是错误的。谁能告诉我这里发生了什么?

解决方案:不同的序言版本。

0 投票
4 回答
1240 浏览

standards - 是否有 ISO-Prolog 参考实现?

Java有一个参考实现

ISO-Prolog 有参考实现吗?

我确实有INCITS/ISO/IEC 13211-1:1995 (R 2007),所以不需要建议。

编辑

注意:一致性测试 I:语法

0 投票
2 回答
482 浏览

prolog - 为什么尽管在 prolog 中使用了 catch 仍然会引发异常?

使用此代码时,会引发此异常并且未返回失败:

在 Sicstus Polog 中:

number_codes/2 中的语法错误!数字语法!在第 0 行

在 SWI-Prolog 中:

错误:number_chars/2:语法错误:非法数字

如何使它在此异常上返回失败。

0 投票
1 回答
869 浏览

operators - 具有相同优先级的 Prolog 中缀运算符一个 xfy 和另一个具有两个顺序运算符的 yfx

在试图理解类型的中缀运算符xfyyfx具有相同的优先级和顺序时,我看到只有四种组合。

使用

现在对于 (xfy xfy)aa运算符都是右结合的。
对于 (yfx yfx) bb,运算符都是左关联的。

然而,对于 (xfy yfx) ab ,(xfy)a运算符是右结合的,而 (yfx)b运算符是左结合的。如果我理解正确,Prolog 会将其评估为:

使用优先级500x意义<y意义<=

对于 (yfx xfy)ba我希望

然而 ISO Prolog 标准写道:

仅当操作数的主函子是右关联运算符时,与在该运算符之前的左关联运算符具有相同优先级的操作数才需要用括号括起来。

带符号:

仅当操作数 (xfy)的主仿函数是右关联运算符时a,与在该运算符 (yfx) 之前的左关联运算符具有相同优先级 (500)的操作数 (xfy)b 才需要括起来a

我理解正确吗?如果是这样,为什么 (xfy yfx)ab需要括号,而 (yfx xfy)ba不需要?

我还寻找了两个具有相同优先级的运算符的实际示例,一个是 xfy,另一个是 yfx,但只找到了Seed7 mult 和 tiimes的一个案例。如果有人可以提供一个更实际的例子abba那将不胜感激。

编辑

在阅读了错误的答案后,这是我的理解。

由于这仅与关联性有关,因此使用 < 和 <= 的规则不适用。
相反,我们使用 Y = Yes, X = No 的含义。

编辑

在寻找具有相同优先级的示例时,xyfyfx发现Meta-Interpreters定义了op(500,xfy,<==).

虽然带有括号的示例是有效的,但您必须使用括号来选择哪个有意义。

0 投票
4 回答
1785 浏览

prolog - 重新排列 variable_names

如何avs_term_rearranged(AVs, T, AVsR)使用给定的标准以符合标准的方式编写AVsTAVsR就是AVs元素的排列顺序相同,因为它们的变量以从左到右的顺序出现在T.

AVs是形式元素的列表,A = V其中A是指定变量名称的原子,如'X'并且V是相应的变量。此类列表由read_term/2,3带有 read-option variable_names/1(7.10.3) 生成。此外,没有定义元素的精确顺序。

T是一个包含所有变量AVs以及更多变量的术语。

请注意,在符合标准的程序中,不能依赖于变量的术语顺序(7.2.1):

7.2.1 变量

如果XY是不相同的变量,则X term_precedes Y应依赖于实现,除非在创建排序列表(7.1.6.5、8.10.3.1 j)期间,排序应保持不变。

注——如果XY都是匿名变量,那么它们不是相同的项(见 6.1.2 a)。

以8.4.3.4为例:

因此,有两种可能的sort/2工作方式,一种甚至不能依赖于:

举个例子:

0 投票
3 回答
2900 浏览

prolog - 在 SWI-Prolog 的 forall 子句中使用成员是否总是以相同的顺序输出元素?

最近进入 Prolog,我一直在使用它来完成一些简单的任务,并开始想知道如何在 forall 循环中使用 member,如下面的简单示例中的那个:

在您执行此类操作的情况下,forall 是否总是会在每次调用时以相同的顺序处理列表中的元素?是否必须通过执行以下操作来强制执行:

根据我最初所做的一些小研究,我猜测它归结为 member/2 的行为,但 SWI-Prolog 网站上的函数文档非常简短。然而,它确实提到了关于 member/2 的确定性,这给了我一个暗示,我可能在正确的道路上说它总是以相同的顺序提取元素,尽管我还不确定。

任何人都可以给我任何保证或解释吗?

0 投票
3 回答
3333 浏览

floating-point - 带有 swi-prolog 的奇怪算术

我觉得结果很奇怪。为什么不是0.3?有人能告诉我为什么会有这个结果吗?有没有可能解决这个问题。

我的第二个问题是如何将“小时”符号“13.45”---->“15.30”转换为小时数?例如,上面计算的 15.30-13.45 期间将是 1.85。但我需要在部分时间而不是剩余的数字上进行操作。像 15 1/2 - 13 /4,这种方式更好。我试试

有什么建议么?

0 投票
3 回答
218 浏览

prolog - Sum 的结果是 floor(Col + Row + 1) 永远不是整数,我不知道为什么

我必须写一段序言,我必须计算数组中的哪个位置用于存储值。然而,这些计算的结果应该返回一个整数,所以我使用floor/1谓词来获取值的整数,但这在我的代码中不起作用。它不断返回一个带小数点的数字,例如 3.0 而不是 3

以下是我的代码:

的结果Sum is floor(Col + Row + 1)永远不是整数,我不知道为什么。谁能帮我这个?

0 投票
1 回答
2265 浏览

prolog - What are the best Prolog programming practices and style guidelines?

OK, I know that this is very general question and that there were written some papers on the subject, but I have a feeling that these publications cover very basic material and I'm looking for something more advanced which would improve style and efficency. This is what I have in paper:

  • "Research Report AI-1989-08 Efficient Prolog: A Practical Guide" by Michael A. Covington, 1989
  • "Efficient Prolog Programming" by Timo Knuutila, 1992
  • "Coding guidelines for Prolog" by Covington, Bagnara, O'Keefe, Wielemaker, Price, 2011

Sample subjects covered in these: tail recursion and differential lists, proper use of indexing, proper use of cuts, avoiding asserts and retracts, avoiding CONSing, code formatting guidelines (indentation, if-then-elses etc.), naming conventions, code documenting, arguments order, testing.

What would you add here from your own personal experience with Prolog? Are there any special style guidelines applicable only to CLP programming? Do you know of some common efficiency problems and know how to deal with them?

UPDATE:

Some interesting (but still too basic and too general for me) points are made here: Prolog programming guidelines of Lifeware Team

Just to highlight the whole problem I would like to qoute "Coding guidelines for Prolog" (Covington et al.):

As far as we know, a coherent and reasonably complete set of coding guidelines for Prolog has never been published. Moreover, when we look at the corpus of published Prolog programs, we do not see a de facto standard emerging. The most important reason behind this apparent omission is that the small Prolog community, due to the lack of a comprehensive language standard, is further fragmented into sub-communities centered around individual Prolog systems, none of which has a dominant position.