How can I use the diagrams tool on regular prolog files?

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
edschwartz
Posts: 3
Joined: Fri Aug 12, 2016 8:45 pm

How can I use the diagrams tool on regular prolog files?

Post by edschwartz » Mon Aug 15, 2016 1:04 pm

Hi,

I am trying to use the diagrams tool to generate a graph of cross-references between rules in a single prolog file. However, I'm not having much luck.

The prolog file is named sdrules.pl. I'm executing:

Code: Select all

logtalk_load(diagrams(loader)).
logtalk_load(sdrules).
Both of these are successful.

But:

Code: Select all

| ?- xref_diagram(dot)::file(sdrules).

no
| ?- xref_diagram(dot)::entity(callDelta).

no
callDelta is the name of a predicate defined in sdrules.

Paulo Moura
Logtalk developer
Posts: 464
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: How can I use the diagrams tool on regular prolog files?

Post by Paulo Moura » Mon Aug 15, 2016 2:16 pm

A simple solution is to define an object that includes the contents of your plain Prolog file. For example:

Code: Select all

:- object(sdrules).

    :- include('sdrules.pl').

:- end_object.
Then, assuming you saved the object definition in a "sdrules.lgt" file (in the same directory as your "sdrules.pl" file) you can use the following queries to generate a predicate cross-referencing diagram:

Code: Select all

?- {diagrams(loader)}, {sdrules}, xref_diagram(dot)::entity(sdrules).
The generated "sdrules_object_xref_diagram.dot" file can then be converted to e.g. PDF:

Code: Select all

$ dot -Tpdf ab_object_xref_diagram.dot > ab_object_xref_diagram.pdf
Hope this helps.
Paulo Moura
Logtalk developer

edschwartz
Posts: 3
Joined: Fri Aug 12, 2016 8:45 pm

Re: How can I use the diagrams tool on regular prolog files?

Post by edschwartz » Mon Aug 15, 2016 5:59 pm

Thanks! That worked great. I'm encountering what I believe is a bug though...

If I have something like this:

caller1 :-
caller2.

caller2 :-
caller1.

caller3 :- caller1.

The xref graph has a cycle between caller1 and caller2, but then no connections to or from caller3.

https://www.dropbox.com/s/j6gt3lg5i702x ... s.pdf?dl=1

There is a lot of recursion and tabling in my real programs, and these missing edges make it very difficult to understand what is going on. Do you have any idea why this is happening?

Paulo Moura
Logtalk developer
Posts: 464
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: How can I use the diagrams tool on regular prolog files?

Post by Paulo Moura » Mon Aug 15, 2016 6:12 pm

I will look into it and get back to you. Thanks for reporting.
Paulo Moura
Logtalk developer

Paulo Moura
Logtalk developer
Posts: 464
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: How can I use the diagrams tool on regular prolog files?

Post by Paulo Moura » Mon Aug 15, 2016 8:29 pm

Can you try the current git version? The fix required only changes to the "core/core.pl" file so we can also simply replace this file in your Logtalk installation.
Paulo Moura
Logtalk developer

edschwartz
Posts: 3
Joined: Fri Aug 12, 2016 8:45 pm

Re: How can I use the diagrams tool on regular prolog files?

Post by edschwartz » Mon Aug 15, 2016 9:24 pm

Thanks! I believe that fixed it. At least, now the graph looks much more like I expected.

This is extremely helpful. Thank you very much for the tool.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest