Information about choicepoints during debugging

20 views
Skip to first unread message

Anne Brecklinghaus

unread,
Sep 21, 2021, 3:29:15 AM9/21/21
to SICStus Users
Hi,

I would like to check the determinism of goals by adding advice-points which check if there are choicepoints for the current debugger goal.

Is there any way in SICStus Prolog to access the information if a goal exited with a choicepoint during debugging?

Kind regards,
Anne

matsc560515

unread,
Sep 21, 2021, 12:06:16 PM9/21/21
to SICStus Users
This functionality is already built in.  Suppose that you have some code:

maybe(yes).
maybe(not).

This session illustrates it:

| ?- trace, maybe(X).
        1      1 Call: maybe(_828) ?
?       1      1 Exit: maybe(yes) ?
X = yes ? ;
        1      1 Redo: maybe(yes) ?
        1      1 Exit: maybe(not) ?
X = not ? ;
no


Note the highlighted "?" on the first Exit and its absence on the second one.  The "?" signals exit with a choicepoint.

Best,

Anne Brecklinghaus

unread,
Sep 24, 2021, 6:12:08 AM9/24/21
to SICStus Users
But is there a way to access this information in code? Without having to read through all debugging messages?

matsc560515

unread,
Sep 24, 2021, 10:15:39 AM9/24/21
to SICStus Users
Yes, the debugger is programmable.  The following manual section discusses how to detect determinism at the Exit port:


If you want to test in your code whether a goal left choicepoints behind, there is no need to resort to the debugger, you can use the trick:

call_det(Goal, Det) :-
    call_cleanup(Goal, Det0=true),
    ( var(Det0) -> Det = nondet ; Det = det ).


This will unify Det with det if no choicepoints were left begind, and with nondet otherwise.

Anne Brecklinghaus

unread,
Sep 25, 2021, 3:13:46 AM9/25/21
to SICStus Users
I've even read about those breakpoint tests before. I don't know how I could have forgotten about it. Thank you!
Reply all
Reply to author
Forward
0 new messages