I have some basic formulas like
female(camilla).
female(diana).
...
parent(person, child).
...
and predicate language/2
that specifies which predicates will I be using:
langugage(female, 1).
language(parent, 2).
What I have to do is to create predicate called body_lit/1
that returns whole clauses specified in language like this:
?- body_lit(X).
X = parent(charles, harry) ;
X = parent(diana, harry) ;
...
X = female(camilla) ;
X = female(diana) ;
...
I know I need to use call/n
function and functor/3
. I know how functor/3
works but I cant seem to figure out how to return the whole clause instead of just the name of the predicate.
I presume that body_lit is supposed to return all answers to predicates given in language with their arities.
body_lit(X) :- language(N,A), functor(F,N,A), call(F), X=F.
language/2
selects a predicate, functor/3
constructs an actual call from the predicate name and its arity, call/1
executes the call, and finally X=F
records the call as the output argument. The last unification could have been removed:
body_lit(X) :- language(N,A), functor(X,N,A), call(X).