0

I'm trying to understand the exact search order of Prolog. In my university course script there are shown traces that show exactly where the "pointer" is at the moment. Let the following be our database:

a(a, a, b).
a(a, a, c).
a(a, a, d).
a(a, a, e).
a(a, a, f).

Then the output of Prolog should be something like this:

?- a(a, a, f).
   a(a, a, b).     fail
   a(a, a, c).     fail
   a(a, a, d).     fail
   a(a, a, e).     fail
   a(a, a, f).     succ

Here I can see exactly where prolog is searching right now and whether the unification is possible or not. This view would be very helpful when trying to understand rules and recursion in Prolog.

I have tried to use trace/0, trace/1 and debug/0. But it just shows me rather confusing and IMO unnecessary information.

Is there a command in Prolog to view something like I mentioned above? Thanks!

Paul Erlenmeyer
  • 523
  • 2
  • 6
  • 29
  • Do you watch the exact trajectory of each and every molecule in your famous flask? No, you don't. For similar reasons it is not too helpful to watch each and every of Prolog's tiny moves. Instead, see [this](https://stackoverflow.com/a/30791637/772868) for better ways. – false Oct 27 '19 at 12:00
  • @false Thanks for your answer. Your link is quite confusing to me, because I have just begun learning prolog and I have no idea of exceptions. Comming from imperative programming I know the order of execution all the time. I want to know the sme for prolog programs (at least when they are small). – Paul Erlenmeyer Oct 28 '19 at 12:22
  • Please look at the linked examples there! (Yes, for the moment you can skip exceptions.) – false Oct 28 '19 at 12:24

1 Answers1

1
  [user] .

  a(a, a, b).
  a(a, a, c).
  a(a, a, d).
  a(a, a, e).
  a(a, a, f).

  end_of_file .

_

  ?- leash(-all) .
  true.

  ?- spy(a) .
  true.

_

  ?- a(P,Q,R) , false ; true .

   * Call: (11) a(_4702, _4704, _4706)
   * Exit: (11) a(a, a, b)
   * Exit: (11) a(a, a, c)
   * Exit: (11) a(a, a, d)
   * Exit: (11) a(a, a, e)
   * Exit: (11) a(a, a, f)
  true.
Kintalken
  • 763
  • 5
  • 9