Write:-repeat,write("hi"),nl,fail.
10
2
このシンプルなものをエディターにロードしたい:
Write:-repeat,write("hi"),nl,fail.
そのため、「hi」と出力されます。
私は何をすべきか?
現在、「ファイル→新規」を実行しようとしています
Writeという名前のファイルを「E:\ Program Files \ pl \ xpce \ prolog \ lib」に保存する
クエリを実行するとき:
?-書きます。
印刷中です。
1 ?- Write. % ... 1,000,000 ............ 10,000,000 years later % % >> 42 << (last release gives the question)
なぜ?
2 回答
8
編集
さらに調査を行いました。 明らかに、インスタンス化されていない変数について尋ねると、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. ?-
最初にファイルを参照する必要があることに注意してください。 私はこれを試してみましたが、確実に機能します。
3
プロシージャに「Write」ではなく「write」という名前を付ける必要があります。 大文字の開始文字は変数用です。 (「writeHi」などのように呼び出すと混乱が少なくなる可能性があるため、組み込みプロシージャと同じ名前はありませんが、「write」を呼び出すと機能します組み込みのものとは異なるアリティを持っています)。
また、 "" hi "`を ’hi'`に置き換えることもできますが、どちらの方法でも機能します(ただし、実際に画面に単語hiを出力するのは2番目のバージョンのみです。バージョンは整数リストとして出力します) 。