1

I am trying to define a predicate looks like "run(ABC, DE)" where ABC is the functor of one of the predicates and DE is its component.

run(ABC, DE) :- ....................
ab(ff).
cc(dd).
ee(ll).

Basically, I am trying to choose ABC as a functor that I want to choose in the database and get the value of DE as its component. For example,

?- run(ab, DE).
DE = ff.

Help plz

bbbBB
  • 65
  • 3

1 Answers1

0

Using the univ (=..) operator you can split a term in a list of its components, check this post

?- funtor(Term1, Term2)=..List.
List = [funtor, Term1, Term2].

?- ab(ff) =.. List2.
List2 = [ab, ff].

?- member(X, [a,b,c]) =.. List3.
List3 = [member, X, [a,b,c]].

Now, all you need to do is create a predicate that will evaluate any list of term, lets call it meta:

meta(L):- Term =.. L, Term.

Now, in your query, you must pass the term with the same syntax used by the univ operator, where the first element of the list is the funtor of the clause you want to evaluate, and the rest of the elements in the list are the arguments for that funtor.

?- meta([ab, X]).
X = ff.
Community
  • 1
  • 1
Yasel
  • 2,920
  • 4
  • 40
  • 48