2

I have a prolog program that has some rather complicated recursive logic. I'd like to visualize the dependency of the rules to better understand the program. Is there some utility that can convert a prolog program to say, a GraphViz file, for visualization?

All of my predicates are contained in one XSB prolog file.

1
  • 2
    In SWI-Prolog, you can try callgraph Commented Mar 28, 2016 at 20:11

1 Answer 1

3

Logtalk (which supports 12 Prolog systems) provides a diagrams tool that can generate several kinds of diagrams, including cross-referencing diagrams. It can also be used with some limitations, depending on the Prolog system, to create diagrams for Prolog code. For example:

http://logtalk.org/diagrams/swi_prolog_library_entity_diagram.svg

An example of a cross-referencing diagram (generated using an old version of tool) is:

http://logtalk.org/diagrams/pengines_module_xref_diagram.pdf

This tool may be a viable option (it's default output is GraphViz .dot files) in your case depending on the Prolog system that you're using and how you organize your code. Maybe you can update your post with some more details?

Sign up to request clarification or add additional context in comments.

5 Comments

Looks like this should do what I want, but I gave it a try, and the call graph is incomplete. For example, I have a predicate foo/4 that calls bar/4. Both of these nodes are in the graph, but that particular edge is missing. Is it possible that cycles in the call graph are not supported?
@EdMcMan I don't think cycles are the problem. Is it possible for you to share part of the code that still allows you to reproduce the issue with the missing edge? Alternatively, feel free to contact me privately by mail (the address can be found at the Logtalk website).
@EdMcMan XSB uses an atom-based module system, which means, among other consequences, a different handling of meta-predicates. Could it be that the missing edge is for a case where the bar/4 predicate is meta-called?
I'll try to reduce to a minimal example. foo/4 does not meta-call bar/4, but there is meta-calling elsewhere in the program.
A bug that most likely explains the missing edges was fixed this week in the Logtalk git version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.