% X belongs to a list if X is at the start of the list | |
---|---|
Element(X, [X|_]) . | |
% or X belongs to a list if the list starts with Y different from X but X belongs to the list 's queue | |
Element(X, [Y|;L]) :- different(X, Y), element(X, L) . | |
a user of a such program asks it like this: | Answer |
>element(9, [5, 3, 4, 7] . | answer = fail |
>element(3, [5, 3, 4, 7] . | answer = ok |
>element(X, [5, 3, 4, 7] . | answer = ok, X = 5 or X = 3 or X = 4 or X = 7 |