add (\=)/2.

This commit is contained in:
Mark Thom
2018-02-14 23:21:56 -07:00
parent a13501dc1a
commit f1ac75f21d
6 changed files with 39 additions and 30 deletions

View File

@@ -85,6 +85,7 @@ The following predicates are built-in to rusty-wam.
* `(==)/2`
* `(\==)/2`
* `(=)/2`
* `(\=)/2`
* `(=..)/2`
* `(->)/2`
* `(;)/2`

View 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> ");

View 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 {

13
src/prolog/lib/control.rs Normal file
View File

@@ -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).";

View 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).";

View File

@@ -1 +1,3 @@
pub mod control;
pub mod lists;