]> Repositorios git - scryer-prolog.git/commitdiff
add (\=)/2.
authorMark Thom <[email protected]>
Thu, 15 Feb 2018 06:21:56 +0000 (23:21 -0700)
committerMark Thom <[email protected]>
Thu, 15 Feb 2018 06:21:56 +0000 (23:21 -0700)
README.md
src/main.rs
src/prolog/ast.rs
src/prolog/lib/control.rs [new file with mode: 0644]
src/prolog/lib/lists.rs
src/prolog/lib/mod.rs

index 4d847d609c2803e1446949fdcdaffc3f67946cca..9934a22a2fe32a948c57639d3cfc0fd7aa712f8d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -85,6 +85,7 @@ The following predicates are built-in to rusty-wam.
 * `(==)/2`
 * `(\==)/2`
 * `(=)/2`
+* `(\=)/2`
 * `(=..)/2`
 * `(->)/2`
 * `(;)/2`
index 62cde4baaca9d820eeb5dc32f21dd9f365c92237..3b4a49003a39c84727baa181a2ed6f4b9f74d146 100644 (file)
@@ -6,6 +6,7 @@ mod prolog;
 #[macro_use] mod test_utils;
 
 use prolog::io::*;
+use prolog::lib::control::*;
 use prolog::lib::lists::*;
 use prolog::machine::*;
 
@@ -35,7 +36,8 @@ fn prolog_repl() {
     let mut wam = Machine::new();
 
     load_init_str(&mut wam, LISTS);
-               
+    load_init_str(&mut wam, CONTROL);
+    
     loop {
         print!("prolog> ");
 
index 9ba74e2fe5fcfcdc4960d5b1ef160c524c81f41b..a66245925a908dd4be4e89dc36a4df1f7e66d73c 100644 (file)
@@ -390,13 +390,13 @@ impl CompareNumberQT {
 }
 
 #[derive(Clone, Copy)]
-pub enum CompareTermQT {
-    GreaterThan,
+pub enum CompareTermQT {    
     LessThan,
-    GreaterThanOrEqual,
     LessThanOrEqual,
-    NotEqual,
-    Equal
+    Equal,
+    GreaterThanOrEqual,
+    GreaterThan,        
+    NotEqual,    
 }
 
 impl CompareTermQT {
diff --git a/src/prolog/lib/control.rs b/src/prolog/lib/control.rs
new file mode 100644 (file)
index 0000000..41ce18b
--- /dev/null
@@ -0,0 +1,13 @@
+pub static CONTROL: &str = ":- op(700, xfx, \\=).
+
+                            once(G) :- G, !.
+
+                            \\=(X, X) :- !, false.
+                            \\=(_, _).
+
+                            between(Lower, Upper, Lower) :-
+                               Lower =< Upper.
+                            between(Lower1, Upper, X) :-
+                               Lower1 < Upper,
+                               Lower2 is Lower1 + 1,
+                               between(Lower2, Upper, X).";
index 7f4f063af02d6b8c8942ec02630139b917d92e85..a584848ab8ebbabdc28d185298f6b4aef0f922d3 100644 (file)
@@ -1,65 +1,56 @@
 pub static LISTS: &str = "member(X, [X|_]).
                           member(X, [_|Xs]) :- member(X, Xs).
-                          
+
                           select(X, [X|Xs], Xs).
                           select(X, [Y|Xs], [Y|Ys]) :- select(X, Xs, Ys).
-                          
+
                           append([], R, R).
                           append([X|L], R, [X|S]) :- append(L, R, S).
-                          
-                          once(G) :- G, !.
-                          
+
                           memberchk(X, Xs) :- member(X, Xs), !.
-                          
+
                           reverse(Xs, Ys) :- reverse(Xs, [], Ys).
-                          
-                          reverse([], Ys, Ys) :- !.
+
+                          reverse([], Ys, Ys).
                           reverse([H|T], Ps, Rs) :-
                               reverse(T, [H|Ps], Rs).
-                          
-                          between(Lower, Upper, Lower) :-
-                             Lower =< Upper.
-                          between(Lower1, Upper, X) :-
-                             Lower1 < Upper,
-                             Lower2 is Lower1 + 1,
-                             between(Lower2, Upper, X).
-                          
+
                           maplist(_, []).
                           maplist(Cont1, [E1|E1s]) :-
                              call(Cont1, E1),
                              maplist(Cont1, E1s).
-                          
+
                           maplist(_, [], []).
                           maplist(Cont2, [E1|E1s], [E2|E2s]) :-
                              call(Cont2, E1, E2),
                              maplist(Cont2, E1s, E2s).
-                          
+
                           maplist(_, [], [], []).
                           maplist(Cont3, [E1|E1s], [E2|E2s], [E3|E3s]) :-
                              call(Cont3, E1, E2, E3),
                              maplist(Cont3, E1s, E2s, E3s).
-                          
+
                           maplist(_, [], [], [], []).
                           maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s]) :-
                              call(Cont, E1, E2, E3, E4),
                              maplist(Cont, E1s, E2s, E3s, E4s).
-                          
+
                           maplist(_, [], [], [], [], []).
                           maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s]) :-
                              call(Cont, E1, E2, E3, E4, E5),
                              maplist(Cont, E1s, E2s, E3s, E4s, E5s).
-                          
+
                           maplist(_, [], [], [], [], [], []).
                           maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s]) :-
                              call(Cont, E1, E2, E3, E4, E5, E6),
                              maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s).
-                          
+
                           maplist(_, [], [], [], [], [], [], []).
                           maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s]) :-
                              call(Cont, E1, E2, E3, E4, E5, E6, E7),
                              maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s, E7s).
-                          
+
                           maplist(_, [], [], [], [], [], [], [], []).
                           maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s], [E8|E8s]) :-
                              call(Cont, E1, E2, E3, E4, E5, E6, E7),
-                             maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s, E7s, E8s).";         
+                             maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s, E7s, E8s).";
index ea55801845db24ccd651000bc59e75e625d96eb2..21c58b2bdb62f1e1944f462aee37b7295cf6ec00 100644 (file)
@@ -1 +1,3 @@
+pub mod control;
 pub mod lists;
+