Download Programming in Pure Prolog

Transcript
128 Programming in Pure Prolog
| ?- app(Xs, Ys, [a,b,a,c]).
Xs = []
Ys = [a,b,a,c] ;
Xs = [a]
Ys = [b,a,c] ;
Xs = [a,b]
Ys = [a,c] ;
Xs = [a,b,a]
Ys = [c] ;
Xs = [a,b,a,c]
Ys = [] ;
no
Combining these two ways of using APPEND we can delete an occurrence of an
element from the list:
| ?- app(X1s, [a | X2s], [a,b,a,c]), app(X1s, X2s, Zs).
X1s = []
X2s = [b,a,c]
Zs = [b,a,c] ;
X1s = [a,b]
X2s = [c]
Zs = [a,b,c] ;
no
Here the result is computed in Zs and X1s and X2s are auxiliary variables. In
addition, we can generate all results of deleting an occurrence of an element from
a list:
| ?- app(X1s, [X | X2s], [a,b,a,c]), app(X1s, X2s, Zs).
X = a
X1s = []
X2s = [b,a,c]
Zs = [b,a,c] ;