Prolog rule dependency graph

Say I want to make a rule dependency graph for a Prolog program in Prolog. For example, the following program

foo(X) :- bar(X, 0).
bar(A, B) :- quux(A), coox(B).
baz.

will result in the following: true (using assert):

depends(foo, [bar]).
depends(bar, [quux, coox]).
depends(baz, []).

Or something like the above that I could easily use to create a graph. The approach I was thinking of is reading the lines of the input file as lines and doing a simple simple search and replace with them, but it looks like an ugly, non-prologue hack. Any other options that use the Prolog's metalogical features?

+3
source share
1 answer

() : Prolog Prolog, () read/1 , . (: -)/2 , Prolog (arg/3, functor/3, =../2 ..). .., .

+2

Source: https://habr.com/ru/post/1775742/


All Articles