当前位置:  开发笔记 > 后端 > 正文

Prolog:制作打印Hello World的程序

如何解决《Prolog:制作打印HelloWorld的程序》经验,为你挑选了1个好方法。

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

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)

为什么?



1> Vivin Paliat..:

编辑

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

UPDATE

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

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.

?- 

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

推荐阅读
linjiabin43
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有