Re:Why Does “=” Mean Assignment?
by kqr on Wednesday April 11, 2018 @12:48AM
(#16808115)
Also not stuck using only an unbound result. Could we not ask "given L and Ls, what elements were dropped?"
[ Parent
| on HN ]
Yes, that's also possible with this definition! For example: Given Ls0 = [a,b,c] and Ls = [a,c], which element (if any) was 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.