Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I design and load my Prolog source files so I don't have to manually use_module?
    primarykey
    data
    text
    <p>I have a source file, openpage.pl, where I call use_module/1 to "import" SWI-Prolog's http_open/3:</p> <pre><code>use_module(library(http/http_open)). request(URL, In) :- http_open(URL, In, []), copy_stream_data(In, user_output), close(In). </code></pre> <p>It loads without complaint. However, try as I might, I can't run it the rules in it.</p> <pre><code>?- [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 </code></pre> <p>So in my next session, I invoke use_module/1 before loading my source file, and all is fine:</p> <pre><code>?- 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). &lt;!doctype html&gt;&lt;html itemscope itemtype="http://schema.org/WebPage"&gt; ... In = &lt;stream&gt;(0x9366508). </code></pre> <p>How can I set up and execute my files so that I don't need this manual step of loading modules before loading my own code?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload