Implement the following predicate:
sublist(Xs, Ys)
this holds when Xs is a list containing some of the elements of Ys,
in the same order they appear in the list Ys. This should work
whenever Ys is a proper list. For example:
sublist([a,c,e](a,b,c,d,el) should succeed.
sublist([a,e,c],[a,b,c,d,el) should fail.
sublist([a,X,d],(a,b,c,d,el) should have the two solutions X=b and
sublist(X,[a,b,c]) should have the eight solutions X=]; X=(cl; X=[bl;
X= b,c; X=a; X=a,c; X= a,b; and X= a,b,c.
Implement the following predicate:
replace(E1, L1, E2, L2)
this holds when list L1 is the same as L2, except that in one place
where L1 has the value E1, L2 has E2. Note that only one
occurrence of E1 is replaced. This must work in any mode in which
at least one of L1 or L2 is a proper list (that is, either I or a list
whose tail is a proper list). For example:
replace(2, 1,2,3,4 ,5,X) should have only the solution X = [1,5,3,4).
replace(2,[1,2,3,2,1,5,X) should backtrack over the solutions X
[1,5,3,2,1] and X = [1,2,3,5,1].
replace(2,,5, [1,5,3,5,1]) should backtrack over the solutions X
[1,2,3,5,1] and X = [1,5,3,2,1].
replace(X,la,b,c,d], Y, la, e,c,d]) should have only the solution X = b, Y
Implement the following predicate:
zip(As, Bs, ABs)
this holds when As, Bs, and ABs are lists of the same length, and
each element of ABs is a term of the form A-B where A is the
corresponding element of As and B is the corresponding element of
Bs. This should work whenever at least one of the arguments is a
proper list. Note that – is an infix operator here, but aside from
syntax, A-B is an ordinary term whose functor is – and whose two
arguments are A and B. For example:
zip([1,2,3,4 ,a,b,c,d ,L) should have only the solution L=[1-a, 2-b, 3-c,4-
zip(X,Y, 1-a,2-b,3-c,4-d) should have only the solution X= 1,2,3,4 , Y=
[a,b,c,d].
zip(11,2,3,4 ,Y, 1-a,2-b,3-c,4-d should have only the solution Y=
[a,b,c,d].
zip(X,[a,b,c,d][1-P,2-Q,3-R,4-S) should have only the solution X=
[1,2,3,4], P=a, Q=b, R=c, S=d.
zip([1,2,3],[a,b,c,d ,L) should fail.