View source with raw comments or as raw
    1r(X, Y) :- r(X, Z), p(Z, Y).     
    2r(X, Y) :- p(X, Y).        
    3% r(a,d) works if goals reversed. Likely r(X, Z) will never succeed with Z = c
    4r(X, Y) :- r(X, Z), q(Z, Y).   
    5p(a, b).   p(b, c).   q(c, d).
    6?- r(a,Y).