Prolog:制作打印Hello World的程序

and*_*and 10 procedure swi-prolog prolog-toplevel

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

Write:-repeat,write("hi"),nl,fail.
Run Code Online (Sandbox Code Playgroud)

所以它打印"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)
Run Code Online (Sandbox Code Playgroud)

为什么?

Viv*_*ath 9

编辑

我做了一些更多的研究.显然,当您询问有关未实例变量的内容时,这就是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)
?- 
Run Code Online (Sandbox Code Playgroud)

UPDATE

将名称更改为小写有效.大写用于变量:

helloworld.prolog:

helloworld:-write('Hello World!'),nl,fail.
Run Code Online (Sandbox Code Playgroud)

然后:

$ 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.

?- 
Run Code Online (Sandbox Code Playgroud)

请注意,您必须先查阅该文件.我尝试了这个,它确实有效.