Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debug information from RunnerState #492

Open
luketpeterson opened this issue Nov 7, 2023 · 0 comments
Open

Improve debug information from RunnerState #492

luketpeterson opened this issue Nov 7, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@luketpeterson
Copy link
Contributor

From here: #469 (comment)

@noskill wrote:

I want to access intermediate steps from python to display execution trace like in swi-prolog, though i will have to make additional PRs since there are too many RunnerState and i have hard time finding important steps of interest e.g. backtracking

memb(X, [X| L]).
memb(X, [_| L]) :-
    memb(X, L).

trace:

[trace] 1 ?- memb(A, [1,2]), memb(A, [2,3]).
   Call: (11) memb(_5772, [1, 2]) ? creep
   Exit: (11) memb(1, [1, 2]) ? creep
   Call: (11) memb(1, [2, 3]) ? creep
   Call: (12) memb(1, [3]) ? creep
   Call: (13) memb(1, []) ? creep
   Fail: (13) memb(1, []) ? creep
   Fail: (12) memb(1, [3]) ? creep
   Fail: (11) memb(1, [2, 3]) ? creep
   Redo: (11) memb(_5772, [1, 2]) ? creep
   Call: (12) memb(_5772, [2]) ? creep
   Exit: (12) memb(2, [2]) ? creep
   Exit: (11) memb(2, [1, 2]) ? creep
   Call: (11) memb(2, [2, 3]) ? creep
   Exit: (11) memb(2, [2, 3]) ? creep
A = 2 ;
   Redo: (11) memb(2, [2, 3]) ? creep
   Call: (12) memb(2, [3]) ? creep
   Call: (13) memb(2, []) ? creep
   Fail: (13) memb(2, []) ? creep
   Fail: (12) memb(2, [3]) ? creep
   Fail: (11) memb(2, [2, 3]) ? creep
   Redo: (12) memb(_5772, [2]) ? creep
   Call: (13) memb(_5772, []) ? creep
   Fail: (13) memb(_5772, []) ? creep
   Fail: (12) memb(_5772, [2]) ? creep
   Fail: (11) memb(_5772, [1, 2]) ? creep
false.

It's not perfect representation, but it easier to read than RunnerState, for example

Call: (11) memb(_5772, [1, 2]) ? creep
Exit: (11) memb(1, [1, 2]) ? creep

call here is the same as in metta, it will try to unify variable, Exit means successful unification _5772=1
then the inference engine tries memb(A=1, [2,3]) and fails
"Redo: (11) memb(_5772, [1, 2]) ? creep" is backtracking to previously tried variant A=1

The same program in metta

        (= (memb $X Nil) False)
        (= (memb $X (Cons $H $Tail))
           (memb $X $Tail))
        (= (memb $X (Cons $X $Tail))
           True)
        !(let $res (and (memb $X (Cons 1 (Cons 2 Nil))) (memb $X (Cons 2 (Cons 3 Nil))))   (if $res $X None))
@luketpeterson luketpeterson added the enhancement New feature or request label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant