Earlier quoted context omitted.
To illustrate how close Erlang syntax is to Prolog, here is drop/3 in Prolog: drop(X, List, Result) :- drop(X, List, [], Result). drop(_, [], Acc, Result) :- reverse(Acc, Result). drop(X, [X|Rest], Acc, Result) :- drop(X, Rest, Acc, Result). drop(X, [Y|Rest], Acc, Result) :- dif(X, Y), drop(X, Rest, [Y|Acc], Result). I only had to make a few syntactic changes to the original program to obtain a Prolog predicate from…
Also not stuck using only an unbound result. Could we not ask "given L and Ls, what elements were dropped?"
?- drop(X, [a,b,c], [a,c]).
X = b ;
false.
As another example, if both Ls0 and Ls are [a,b,c]: ?- drop(X, [a,b,c], [a,b,c]).
dif(X, c),
dif(X, b),
dif(X, a).
This means that X must be different from each of these elements.More generally, which elements can be dropped at all from the list [a,b,c]:
?- drop(X, [a,b,c], _).
X = a ;
X = b ;
X = c ;
dif(X, c),
dif(X, b),
dif(X, a).
Interestingly, the predicate definition does not even use "=" in its clauses. In Prolog, (=)/2 is a built-in predicate that means unification. In the definition above, we use implicit unification instead of explicit unification.