本文介绍了七周内七种语言的 Prolog 存在错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在看《七周内的七种语言》这本书.

I'm just following the book Seven Languages in Seven Weeks.

我已经使用命令 port install gprolog-devel 在我的 Mac 机器上安装了 gprolog 并运行了第一个 prolog 代码.

I've installed gprolog in my Mac machine using command port install gprolog-devel and run first prolog code.

likes(wallace, cheese).
likes(grommit, cheese).
likes(wendolene, sheep).

friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).

如果我在 prolog 解释器上输入 likes(wallace, cheese).,我有错误

If I type likes(wallace, cheese). on prolog interpretor, I've got error

未捕获的异常:error(existence_error(procedure,likes/2),top_level/0).

无法在我的 Mac 上安装 Prolog 1.3.1,我使用的是 prolog 1.4.0.

Prolog 1.3.1 could not be installed in my Mac, I'm using prolog 1.4.0.

推荐答案

交互式 gprolog 解释器针对加载的谓词列表运行查询,这就是您收到 existence_error 异常的原因.您必须将谓词加载到其中,方法是使用为您加载的 IDE 或手动加载.

The interactive gprolog interpreter runs queries against a loaded list of predicates, that is why you get the existence_error exception. You will have to load your predicates into it, either by using an IDE that does the loading for you or doing it manually.

这是一种方法:

| ?- [user].
compiling user for byte code...
likes(wallace, cheese).
likes(grommit, cheese).
likes(wendolene, sheep).

friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).

* Press Ctrl-D to end input. *
user compiled, 6 lines read - 909 bytes written, 15538 ms

yes
| ?- friend(wallace,grommit).

yes
| ?- friend(wallace,wendolene).

no

gprolog 手册在咨询 Prolog 程序

The gprolog manual writes about this in the chapter Consulting a Prolog program

这篇关于七周内七种语言的 Prolog 存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 21:01