]> Repositorios git - scryer-prolog.git/commitdiff
add tests for module resolution operator, README documentation.
authorMark Thom <[email protected]>
Mon, 9 Jul 2018 01:49:15 +0000 (19:49 -0600)
committerMark Thom <[email protected]>
Mon, 9 Jul 2018 01:49:15 +0000 (19:49 -0600)
README.md
src/prolog/compile.rs
src/tests.rs

index 5629e7ae273df73704f8e29f30386b6ac169f5ed..a82b3e03f93c8721ea454b99f50dbdfec8ea07fb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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.
\ No newline at end of file
index d2906acbaf2496caa84ce5bb313ca01995a6ac68..c6691676461e781486cdfe51043b086581297751 100644 (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)
             },
index d0d811a18d763fc9e5b843bcab9b0f6d91d2517a..0cd3d0328f8c097432a7ce34bf862b4e044ae2b2 100644 (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()
 {