我想将这个简单的东西加载到我的编辑器中:

Write:-repeat,write("hi"),nl,fail.

这样就可以打印“hi”。

我应该怎么办?

我目前正在尝试File->New
并保存名为Write的文件到E:\Program Files\pl\xpce\prolog\lib
执行查询时:

?-写。

正在打印:
1 ?- Write.
% ... 1,000,000 ............ 10,000,000 years later
%
%       >> 42 << (last release gives the question)

为什么?

最佳答案

编辑

我做了更多的研究。显然,这是SWI-Prolog在询问未实例化变量时所做的事情。

$ prolog
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.6.64)
Copyright (c) 1990-2008 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- X.
% ... 1,000,000 ............ 10,000,000 years later
%
%       >> 42 << (last release gives the question)
?-

更新

将名称更改为小写即可。大写字母表示变量:

helloworld.prolog:
helloworld:-write('Hello World!'),nl,fail.

然后:
$ prolog
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.6.64)
Copyright (c) 1990-2008 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- ['helloworld.prolog'].
% helloworld.prolog compiled 0.00 sec, 1,376 bytes
true.

?- helloworld.
Hello World!
false.

?-

请注意,您必须先查阅该文件。我尝试了一下,它肯定可以工作。

10-06 10:47
查看更多