add tests for module resolution operator, README documentation.

This commit is contained in:
Mark Thom
2018-07-08 19:49:15 -06:00
parent cd03b7795f
commit 89044266d6
3 changed files with 34 additions and 5 deletions

View File

@@ -280,11 +280,9 @@ prolog> :- use_module(library(lists), [member/2]).
A qualified `use_module` can be used to remove imports from the
toplevel by calling it with an empty import list.
The `(:)/2` operator is used to resolve calls to predicates
not within the current working namespace:
The `(:)/2` operator resolves calls to predicates that might not be
imported to the current working namespace:
```
prolog> ?- lists:member(X, Xs).
```
This is a debugging kludge. Mostly.

View File

@@ -138,7 +138,7 @@ pub fn compile_packet(wam: &mut Machine, tl: TopLevelPacket) -> EvalSession
{
match tl {
TopLevelPacket::Query(terms, queue) =>
match compile_query(terms, queue) { //, &mut wam.code_dir) { //wam.code_size(), &mut wam.code_dir) {
match compile_query(terms, queue) {
Ok((mut code, vars)) => wam.submit_query(code, vars),
Err(e) => EvalSession::from(e)
},

View File

@@ -1266,6 +1266,37 @@ fn test_queries_on_conditionals()
[["X = a"], ["X = b"]]);
}
#[test]
fn test_queries_on_modules()
{
let mut wam = Machine::new();
wam.use_module_in_toplevel(clause_name!("lists"));
compile_user_module(&mut wam, "
:- module(my_lists, [local_member/2, reverse/2]).
:- use_module(library(lists), [member/2]).
local_member(X, Xs) :- member(X, Xs).
reverse(Xs, Ys) :- lists:reverse(Xs, Ys).
");
assert_prolog_success!(&mut wam, "?- my_lists:local_member(1, [1,2,3]).");
assert_prolog_success!(&mut wam, "?- my_lists:reverse([a,b,c], [c,b,a]).");
compile_user_module(&mut wam, "
:- use_module(library(my_lists), [local_member/2]).
:- module(my_lists_2, [local_member/2]).
");
assert_prolog_success!(&mut wam, "?- my_lists_2:local_member(1, [1,2,3]).");
assert_prolog_success!(&mut wam, "?- catch(local_member(X, Xs), error(E, _), true).",
[["X = _1", "E = existence_error(procedure, local_member/2)", "Xs = _2"]]);
}
#[test]
fn test_queries_on_builtins()
{