$findterm/5 — locates the given term on the heap
' $findterm '(Functor, Arity, HeapPos, Term, NewHeapPos)
The term whose
Arity are given is searched for on the heap starting from the given heap position
HeapPos. If the term is located, the fourth argument,
Term, is unified with the term found in the heap, and the fifth argument,
NewHeapPos, is unified with a pointer to the next heap location after the term found. Heap positions are offsets with respect to the heap base. If the term cannot be found, this predicate fails.
?- X = f(a,b), '$findterm'(f, 2, 0, T, NHP). X = f(a,b) T = f(a,b) NHP = 3 yes.