处理导致编译失败的动态谓词

时间:2021-02-24 00:59:55

标签: prolog gnu-prolog

我正在尝试运行一个示例 GNU Prolog 程序,在我的课程工作中用作示例。代码是直接从 https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_17pl.txt 中提取的,并且我的教授曾展示过它的工作原理。

但是,当我运行提供的示例代码时,我收到以下编译警告:

| ?- consult('C:/Users/Chase/Desktop/Prolog files/newAnimal.pro').
compiling C:/Users/Chase/Desktop/Prolog files/newAnimal.pro for byte code...
C:/Users/Chase/Desktop/Prolog files/newAnimal.pro:74:12: syntax error: . or operator expected after expression
    1 error(s)
compilation failed

阻止程序正确编译的行是:

:- dynamic yes/1,no/1.

我在这里读到的:https://www.swi-prolog.org/pldoc/man?predicate=dynamic/1

然而,尽管尝试重写和重新格式化该部分,我仍然无法编译它。

有关为什么提供的代码可能无法运行的任何帮助?

我使用的是 Windows GUI GNU Prolog 控制台 V1.4.5

1 个答案:

答案 0 :(得分:2)

ISO Prolog 标准不要求将 qputenv("PATH", qgetenv("PATH")); // this line fixes the issue (或 dynamicmultifile)声明为运算符。一些系统这样做(例如你提到的 SWI-Prolog),但不是 GNU Prolog。因此,为确保代码可移植性,请避免使用 discontiguous 作为运算符。改写:

dynamic

或者:

:- dynamic(yes/1).
:- dynamic(no/1).

或者:

:- dynamic((yes/1, no/1)).

这些是将多个谓词声明为动态的符合标准的替代方案。

此外,GNU Prolog 有一个很好的手册(安装的一部分),您在使用 GNU Prolog 时应该参考。