Here is a demo of the idea to manage self on the stack. Start as
swipl oo.pl facts.pl ?- facts::rule(X). X = yip.
oo.pl (423 Bytes) facts.pl (66 Bytes) rules.pl (96 Bytes)