add tests for module resolution operator, README documentation.
This commit is contained in:
@@ -280,11 +280,9 @@ prolog> :- use_module(library(lists), [member/2]).
|
|||||||
A qualified `use_module` can be used to remove imports from the
|
A qualified `use_module` can be used to remove imports from the
|
||||||
toplevel by calling it with an empty import list.
|
toplevel by calling it with an empty import list.
|
||||||
|
|
||||||
The `(:)/2` operator is used to resolve calls to predicates
|
The `(:)/2` operator resolves calls to predicates that might not be
|
||||||
not within the current working namespace:
|
imported to the current working namespace:
|
||||||
|
|
||||||
```
|
```
|
||||||
prolog> ?- lists:member(X, Xs).
|
prolog> ?- lists:member(X, Xs).
|
||||||
```
|
```
|
||||||
|
|
||||||
This is a debugging kludge. Mostly.
|
|
||||||
@@ -138,7 +138,7 @@ pub fn compile_packet(wam: &mut Machine, tl: TopLevelPacket) -> EvalSession
|
|||||||
{
|
{
|
||||||
match tl {
|
match tl {
|
||||||
TopLevelPacket::Query(terms, queue) =>
|
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),
|
Ok((mut code, vars)) => wam.submit_query(code, vars),
|
||||||
Err(e) => EvalSession::from(e)
|
Err(e) => EvalSession::from(e)
|
||||||
},
|
},
|
||||||
|
|||||||
31
src/tests.rs
31
src/tests.rs
@@ -1266,6 +1266,37 @@ fn test_queries_on_conditionals()
|
|||||||
[["X = a"], ["X = b"]]);
|
[["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]
|
#[test]
|
||||||
fn test_queries_on_builtins()
|
fn test_queries_on_builtins()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user