0

ソースファイルopenpage.plがあり、use_module/1を呼び出してSWI-Prologのhttp_open/3を「インポート」します。

use_module(library(http/http_open)).

request(URL, In) :- http_open(URL, In, []),
    copy_stream_data(In, user_output),
    close(In).

それは文句なしにロードされます。ただし、できる限り試してみてください。ルールを実行することはできません。

?- [openpage].
% openpage compiled 0.00 sec, 1,828 bytes
true.

?- request('http://www.google.com', In).
ERROR: request/2: Undefined procedure: http_open/3
?- use_module(library(http/http_open)).
true.

?- request('http://www.google.com', In).
ERROR: request/2: Undefined procedure: http_open/3
?- make.
% Scanning references for 1 possibly undefined predicates
Warning: The predicates below are not defined. If these are defined
Warning: at runtime using assert/1, use :- dynamic Name/Arity.
Warning: 
Warning: http_open/3, which is referenced by
Warning:    status/2 at /home/dale/sesame_test/prolog/openpage.pl:16
Warning:    request/2 at /home/dale/sesame_test/prolog/openpage.pl:3
Warning:    modified/2 at /home/dale/sesame_test/prolog/openpage.pl:7
true.

?- [openpage].
% openpage compiled 0.00 sec, 616 bytes
true.

?- request('http://www.google.com', In).
ERROR: request/2: Undefined procedure: http_open/3
?- 
[forced] Action (h for help) ? exit

したがって、次のセッションでは、ソースファイルをロードする前にuse_module / 1を呼び出しますが、すべて問題ありません。

?- use_module(library(http/http_open)).
%  library(uri) compiled into uri 0.00 sec, 199,772 bytes
%  library(readutil) compiled into read_util 0.00 sec, 10,312 bytes
%  library(socket) compiled into socket 0.00 sec, 6,376 bytes
%  library(option) compiled into swi_option 0.00 sec, 7,748 bytes
%  library(base64) compiled into base64 0.00 sec, 9,776 bytes
%  library(debug) compiled into prolog_debug 0.01 sec, 12,056 bytes
% library(http/http_open) compiled into http_open 0.01 sec, 282,844 bytes
true.

?- [openpage].
% openpage compiled 0.00 sec, 1,380 bytes
true.

?- request('http://www.google.com/', In).
<!doctype html><html itemscope itemtype="http://schema.org/WebPage">
...
In = <stream>(0x9366508).

自分のコードをロードする前にモジュールをロードするこの手動の手順を必要としないように、ファイルをセットアップして実行するにはどうすればよいですか?

4

1 に答える 1

5

試す:

:- use_module(library(http/http_open)).

ソースファイル内。

于 2012-06-15T17:41:27.067 に答える