1. Carl Friedrich Bolz
  2. Pyrolog

Commits

Ed Robbins  committed 5395589

Replace GPL list predicates with MIT license cleanroom implementations.

  • Participants
  • Parent commits 2e28267
  • Branches default

Comments (0)

Files changed (1)

File prolog/prolog_modules/list.pl

View file
  • Ignore whitespace
-:- module(list, [append/3, member/2, is_list/1, select/3, nextto/3, memberchk/2, subtract/3, min_member/2, max_member/2]).
+:- module(list, [append/3, member/2, is_list/1, select/3, nextto/3, memberchk/2, subtract/3, min_member/2, max_member/2, delete/3]).
 
 append([], L, L).
 append([H|T], L, [H|R]) :- append(T, L, R).
 is_list([]).
 is_list([_|T]) :- is_list(T).
 
-% borrowed from SWI prolog
-select(X, [X|Tail], Tail).
-select(Elem, [Head|Tail], [Head|Rest]) :-
-	select(Elem, Tail, Rest).
-
-% borrowed from SWI prolog
-nextto(X, Y, [X,Y|_]).
-nextto(X, Y, [_|Zs]) :-
-	nextto(X, Y, Zs).
-
-memberchk(Elem, List) :-
-	once(member(Elem, List)).
-
-% borrowed from SWI prolog
-subtract([], _, []) :- !.                                                       
-subtract([E|T], D, R) :-                                                        
-	memberchk(E, D), !,                                                     
-	subtract(T, D, R).                                                      
-subtract([H|T], D, [H|R]) :-                                                    
-	subtract(T, D, R).
-
 % min_member/2
 min_member(Result, [H | T]) :-
 	min_member(H, T, Result).
 max_member(BestIn, [H | T], BestOut) :-
 	(BestIn @> H -> BestDown = BestIn; BestDown = H),
 	max_member(BestDown, T, BestOut).
+
+% subtract/3
+subtract(Rest, [], Rest).
+subtract(_, Delete, _) :-
+	var(Delete), !, fail.
+subtract(Set, [Elem | Delete], Result) :-
+	delete(Set, Elem, Rest),
+	subtract(Rest, Delete, Result), !.
+
+% delete/3
+delete([], _, []).
+delete([Elem | List1], Elem, List2) :-
+	delete(List1, Elem, List3), !,
+	List2 = List3.
+delete([Head | List1], Elem, List2) :-
+	delete(List1, Elem, List3),
+	List2 = [Head | List3].
+
+% memberchk/3
+memberchk(Elem, [Elem | _]) :- !.
+memberchk(Elem, [_ | List]) :-
+	memberchk(Elem, List).
+
+% nextto/3
+nextto(X, Y, [A, B | _]) :-
+	X = A, Y = B, true.
+nextto(X, Y, [_, B | List]) :-
+	nextto(X, Y, [B | List]).
+
+% select/3
+select(Elem, [Elem | List1], List1).
+select(Elem, [Head | List1], [Head | List3]) :-
+	select(Elem, List1, List3).