Printing debug message only after a redo due to fail

Hi,

I have predicates p1 and p2. p2 is always evetually called after p1. If p2 fails then a choice point in p1 becomes chosen.

I want to write a debug message immediately after that choice point, and it should write a message only during a redo.

Is this possible?

thank you,

Dan

I guess the simplest way is to split p1 into two and have a second p1 continue where the first failed.

No need really to look at the frame stack or something …

on “third” thoughts – this woudlnt work …

since there would be many possible redo s and different levels.

Looks like i need to think this through some further.

I’m guessing your code is something like this:

p1 :- p0, p2, p3.
p1 :- something_else.

p2 :- ... % something that can fail

To get your message printed, you could change the code to something like this:

p1 :- p0, p2, p3.
p1 :- writeln('failure inside p1'), fail.
p1 :- something_else.

Or you could replace the call to p2 by this (which doesn’t allow backtracking into another solution from p2):

( p2 -> true ; writeln('p2 failed'), fail )

Or, allowing backtracking into p2:

( p2 ; writeln('p2 failed'), fail )

Your situation might be different, but these should give you a starting point.