http:location false in shell but not in source code

22 views
Skip to first unread message

Bambang Purnomosidi D. P.

unread,
Aug 2, 2014, 10:42:02 AM8/2/14
to swi-p...@googlegroups.com
Dear list,

I don't understand why http:location here has 'false' result:

?- use_module(library(http/http_path)).
true.

?- dynamic   http:location/3.
true.

?- multifile http:location/3.
true.

?- http:location(assets, root('assets'), []).
false.

 ?- http:location(assets, root(assets), []).
false.

While when I put that inside a file, It does work:

:- use_module(library(http/http_server_files)).
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_path)).
:- multifile user:file_search_path/2.

http:location(assets, root('assets'), []).

file_search_path(assets_root, 'assets').
file_search_path(assets, assets_root(.)).

:- http_handler(assets(.), serve_files_in_directory(assets), [prefix]).

server(Port) :-
    http_server(http_dispatch, [port(Port)]).

Can someone please shed a light? thank you.

Jan Wielemaker

unread,
Aug 3, 2014, 6:43:23 AM8/3/14
to Bambang Purnomosidi D. P., swi-p...@googlegroups.com
Dear Bambang,

You missed the fact that Prolog operates in a different mode
when reading from the user than it does when reading a file.

If it reads a file, all terms are by default interpreted as
new clauses that are added to the database. Only terms that
start with `:-` are interpreted as commands (well, directives,
but let me keep things simple).

In contrast, the toplevel interprets any term typed as a
_query_ and will try to prove it. If you really want to
add something to the database, you can either use assertz/1:

?- assertz(http:location(assets, root('assets'), [])).

or consult `user`:

?- [user].
|: http:location(assets, root('assets'), []).
|: <type Control-D>
?-

Hope this helps

--- Jan
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Bambang Purnomosidi D. P.

unread,
Aug 3, 2014, 8:01:57 PM8/3/14
to swi-p...@googlegroups.com, bamba...@gmail.com
Dear Jan,

Thank you for replying my trivial question patiently. It sure helps me. Thanks again.
Reply all
Reply to author
Forward
0 new messages