prologvisualizationvisualizer

How do I see a detailed order (execution) for a Prolog query?


Let's say I have this Prolog program:

loves(vincent, mia).
loves(marcellus, mia).
jealous(A, B) :- loves(A, C), loves(B, C).

With query jealous(A,B). I'm very new to Prolog and I'd like to know how is it possible to see the exact order the program will be running and taking its ways for this query? I have tried using trace, jealous(A,B). command but it has only given me that:

Isn't there any more detailed solution for that? :/

enter image description here


Solution

  • Have you seen the Prolog Visualizer?

    When you get to the page be sure to click on the icons in the upper right to learn more.

    enter image description here

    Enjoy.


    Screenshot after step 10 of 49.

    enter image description here

    Screenshot for example given after all steps.

    enter image description here


    The Prolog Visualizer uses a slightly nonstandard way to enter a query by ending the query with a question mark (?), e.g.

    jealous(A,B)?
    

    If you do not post a query in the input area on the left you will receive an error, e.g.

    enter image description here

    The input for the Prolog Visualizer for your example is

    loves(vincent, mia).
    loves(marcellus, mia).
    jealous(A, B) :- loves(A, C), loves(B, C).
    jealous(A,B)?
    

    When the Prolog Visualizer completes your example, notice the four results in green on the right

    enter image description here


    If you are using SWI-Prolog and after you understand syntactic unification, backtracking and write more advanced code you will find this of use:

    Overview of the SWI Prolog Graphical Debugger


    For other useful Prolog references see: Useful Prolog references