1

Let's say I have this scenario:

ascendent(X,Y) :- parent(X,Y).
ascendent(X,Y) :- parent(X,Z), ascendent(Z,Y).

brother(X,Y):-parent(Z,X),parent(Z,Y), X \= Y .
uncle(X,Y):-brother(X,Z),parent(Z,Y),X \= Y.

How can I know the predicates used by ascendent and the predicates that uses ascendent? Is there any built-in function or meta-predicate useful for this task?

Tomcat
  • 606
  • 6
  • 18
ameyer
  • 13
  • 4
  • What do you mean by "know"? At what point do you need the information, and what are you going to do with it? –  May 13 '13 at 18:22
  • I'm going to print the dependency tree for a given predicate. – ameyer May 13 '13 at 18:25
  • Does exists any kind of 'reflection' mechanisms for prolog? I'm learning this language from scratch. – ameyer May 13 '13 at 18:32
  • Well, you can use `listing` and parse the output.... I don't know of any "proper" way to do it. Finding the dependency tree seems to be a task that will duplicate the role of the interpreter, so I guess you would need to build a meta-interpreter to do this. Do you need to do it on source-code or on a compiled program, from inside the program? –  May 13 '13 at 18:41
  • I need to do this on source code. Specifically I should consult a given prolog source code file, check if an input given predicate is present and print the dependency tree for this (if it exists). – ameyer May 13 '13 at 18:44
  • 1
    _The Craft of Prolog_ discusses writing a Prolog interpreter in Prolog, and much of the material in _Prolog Programming in Depth_ is based on meta-interpretation. It's not all that hard to do, and it is Prolog's most complete answer to reflection. There are [other ways to get access to the running Prolog image](http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%274.15%27,swi%28%27/doc/Manual/examineprog.html%27%29%29) but I don't think they let you examine the internal makeup of predicates (except for `listing`). – Daniel Lyons May 13 '13 at 18:48

0 Answers0