projog

3.120. include(X,Y,Z) - filters a list by a goal.

include(X,Y,Z) succeeds if the list Z consists of the elements of the list Y for which the goal X can be successfully applied.

Examples

?- include(atom, [], []).

yes

?- include(atom, [a], [a]).

yes

?- include(atom, [X], []).
X = UNINSTANTIATED VARIABLE

yes

?- include(atom, [1], []).

yes

?- include(integer, [1], [1]).

yes

?- include(atom, [a,a,a], X).
X = [a,a,a]

yes

?- include(atom, [a,b,c],X).
X = [a,b,c]

yes

?- include(atom, [1,b,c], X).
X = [b,c]

yes

?- include(atom, [a,2,c], X).
X = [a,c]

yes

?- include(atom, [a,b,3], X).
X = [a,b]

yes

?- include(atom, [a,2,3], X).
X = [a]

yes

?- include(atom, [1,b,3], X).
X = [b]

yes

?- include(atom, [1,2,c], X).
X = [c]

yes

?- include(atom, [1,2,3], X).
X = []

yes

?- include(<(0), [5,6,1,8,7,4,2,9,3], [5,6,1,8,7,4,2,9,3]).

yes

?- include(<(0), [5,6,1,8,7,4,2,9,3], X).
X = [5,6,1,8,7,4,2,9,3]

yes

?- include(>(5), [5,6,1,8,7,4,2,9,3], X).
X = [1,4,2,3]

yes

?- include(>(7), [5,6,1,8,7,4,2,9,3], X).
X = [5,6,1,4,2,3]

yes

?- include(>(7), [5,6,1,8,7,4,2,9,3], [5,6,1,4,2,3]).

yes

?- include(=(7), [5,6,1,8,7,4,2,9,3], X).
X = [7]

yes

?- include(=(0), [5,6,1,8,7,4,2,9,3], X).
X = []

yes

?- include(=(p(W)), [p(1),p(2),p(3)], Z).
W = 1
Z = [p(1)]

yes

?- include(=(p(1,A,3)), [p(W,a,4), p(X,b,3), p(X,Y,3), p(Z,c,3)], B).
A = b
B = [p(1, b, 3),p(1, b, 3)]
W = UNINSTANTIATED VARIABLE
X = 1
Y = b
Z = UNINSTANTIATED VARIABLE

yes

First argument must be an atom or structure. Second argument must be a list.

?- include(X, [], Z).

no

?- include(1, [], Z).

no

?- include(atom, X, Z).

no

Note: "sublist" is a synonym for "include".

?- sublist(atom, [a,b,c], X).
X = [a,b,c]

yes

?- sublist(atom, [a,2,c], X).
X = [a,c]

yes

p(a) :- writeln('rule 1').
p(b) :- writeln('rule 2').
p(X) :- atom(X), writeln('rule 3').

?- include(p,[1,a,2,b,3,c,c,4,c,b,5,a,z,b,b,6], Z).
rule 1
rule 2
rule 3
rule 3
rule 3
rule 2
rule 1
rule 3
rule 2
rule 2
Z = [a,b,c,c,c,b,a,z,b,b]

yes