In Prolog (unlike Python), if two things look the same they are the same. An uninstantiated variable in Prolog is similar to a pointer in conventional programming language. (Explaining Python’s memory model requires a long digression, which you can find by looking for tutorials on
is, for example.)
Of course, there are some details to the “look the same, are the same”:
- “look the same” is using something like
write_canonical/1, without using
=/2 succeeds if the two terms unify.
==/2 can be used to check whether two unistantiated variables are the same (but they might subsequently become the same with a subsequent unifcation).
=@=/2 can check whether two terms would unify, without instantiating variables.
=@=/2 are non-logical operations, as are
ground/1. They usually aren’t needed; if you find you do need them, you should consider changing your program so that they aren’t needed.