For my programming course's assignment, I have to write some Prolog code without using any pre-defined predicates (excluding ,
and ;
), but saw no way around using =
, as I had to check whether a variable A
is equal to (can be identified with) some foo(B, C)
.
Since this isn't allowed though, I'd like to implement my own predicate myUnification/2
, which should essentially behave in the same way, but I have no idea how to go about this. I've tried looking at the SWI-Prolog Documentation for assistance but it only explains what the predicate does, not how it actually works internally.
It is right there in the docs :-D
=(Term, Term).
To use 'unify' instead of '=', define:
unify(A, A).
You can now do magic like this:
?- unify(X, foo(a, b)).
X = foo(a, b).