12

この単純なものをエディターにロードしたい:

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

「こんにちは」と出力されるようにします。

私は何をすべきか?

私は現在やろうとしています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)

なんで?

4

2 に答える 2

10

編集

さらに調査を行いました。どうやらこれは、インスタンス化されていない変数について SWI-Prolog に尋ねると、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.

?- 

最初にファイルを参照する必要があることに注意してください。私はこれを試してみましたが、確かに機能します。

于 2010-03-31T20:33:43.077 に答える
3

プロシージャに名前を付ける必要があります。writeではありませんWrite。大文字の開始文字は変数用です。(他の名前などと呼んでも混乱が少ないかもしれませんwriteHi。そのため、組み込みのプロシージャと同じ名前ではありませんが、write書き込みのアリティがビルトインワン)。

"hi"また、どちらの方法でも機能しますが、に置き換えることもできます'hi'(ただし、実際には2番目のバージョンのみがhiという単語を画面に出力します。バージョンは整数リストとして出力します)。

于 2010-03-31T20:42:48.903 に答える