make sublist from hprolog and sublist from yap be the same beast.

This commit is contained in:
Vitor Santos Costa 2010-03-15 14:19:05 +00:00
parent 9cce7df45b
commit cfc0a23953
2 changed files with 35 additions and 21 deletions

View File

@ -38,7 +38,7 @@
split_at/4, % +N, +List, -FirstElements, -LastElements split_at/4, % +N, +List, -FirstElements, -LastElements
max_go_list/2, % +List, -Max max_go_list/2, % +List, -Max
or_list/2, % +ListOfInts, -BitwiseOr or_list/2, % +ListOfInts, -BitwiseOr
chr_sublist/2, % ?Sublist, +List sublist/2, % ?Sublist, +List
bounded_sublist/3, % ?Sublist, +List, +Bound bounded_sublist/3, % ?Sublist, +List, +Bound
chr_delete/3, chr_delete/3,
init_store/2, init_store/2,
@ -54,7 +54,10 @@
put_ds/4 put_ds/4
% lookup_ht1/4 % lookup_ht1/4
]). ]).
:- use_module(library(lists)).
:- reexport('../lists',[sublist/2]).
%:- use_module(library(lists)).
:- use_module(library(assoc)). :- use_module(library(assoc)).
/** <module> hProlog compatibility library /** <module> hProlog compatibility library
@ -210,15 +213,15 @@ or_list([H|T], Or0, Or) :-
% %
% True if all elements of Sub appear in List in the same order. % True if all elements of Sub appear in List in the same order.
chr_sublist(L, L). %sublist(L, L).
chr_sublist(Sub, [H|T]) :- %sublist(Sub, [H|T]) :-
'$sublist1'(T, H, Sub). % '$sublist1'(T, H, Sub).
'$sublist1'(Sub, _, Sub). %'$sublist1'(Sub, _, Sub).
'$sublist1'([H|T], _, Sub) :- %'$sublist1'([H|T], _, Sub) :-
'$sublist1'(T, H, Sub). % '$sublist1'(T, H, Sub).
'$sublist1'([H|T], X, [X|Sub]) :- %'$sublist1'([H|T], X, [X|Sub]) :-
'$sublist1'(T, H, Sub). % '$sublist1'(T, H, Sub).
%% bounded_sublist(?Sub, +List, +Bound:integer) %% bounded_sublist(?Sub, +List, +Bound:integer)
% %

View File

@ -267,10 +267,21 @@ select(Element, [Head|Tail], [Head|Rest]) :-
% sublist(Sublist, List) % sublist(Sublist, List)
% is true when both append(_,Sublist,S) and append(S,_,List) hold. % is true when both append(_,Sublist,S) and append(S,_,List) hold.
sublist(Sublist, List) :- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
prefix(Sublist, List).
sublist(Sublist, [_|List]) :- %% sublist(?Sub, +List) is nondet.
sublist(Sublist, List). %
% True if all elements of Sub appear in List in the same order.
sublist(L, L).
sublist(Sub, [H|T]) :-
'$sublist1'(T, H, Sub).
'$sublist1'(Sub, _, Sub).
'$sublist1'([H|T], _, Sub) :-
'$sublist1'(T, H, Sub).
'$sublist1'([H|T], X, [X|Sub]) :-
'$sublist1'(T, H, Sub).
% substitute(X, XList, Y, YList) % substitute(X, XList, Y, YList)
% is true when XList and YList only differ in that the elements X in XList % is true when XList and YList only differ in that the elements X in XList