prolog delete head from a clause

87 views Asked by At

I am using yap. Suppose I have this scenario:

p(x,y) :- q(x), f(x,y), g(x).

I need to put the body of the predicate in a list using the command listing(p).

Expected output should be: [q,f,g].

How I can do that?

1

There are 1 answers

0
CapelliC On

with a service predicate

enum_conj((A, B),X) :- !, (enum_conj(A, X) ; enum_conj(B, X)).
enum_conj(X, X).

we can do

?- clause(p(_, _), P), setof(F, J^A^(enum_conj(P, J), functor(J, F, A)), L).
L = [f,g,q],
P = (q(x),f(x,y),g(x))

all builtins used are ISO standard