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.
\ No newline at end of file
{
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)
},
[["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()
{