All Manuals > KnowledgeWorks and Prolog User Guide > A Common Prolog > A.7 Debugging

NextPrevUpTopContentsIndex

A.7.4 Interactive Debugging

When Common Prolog execution enters a debugging command loop, the user has many options, which may be listed with ?, for example:

|==> (spy member)
|
|((MEMBER 2)) 
|YES.
|OK. 
|
|==> (member 3 ?x)
|
|[1] CALL: (MEMBER 3 ?0)? ? <- user types ?
|
|(c)reep     - turn on exhaustive tracing
|(s)kip      - skip until another port is 
|              reached for this goal
|(l)eap      - turn off tracing until a spy
|              point or this goal is reached
|(b)reak     - enter a recursive 
|              read/query/print loop
|(d)isplay   - display a listing for the
|              current goal
|(q)uit      - quit to top level
|(r)etry     - try to satisfy this goal again
|(f)ail      - cause the current goal to fail
|(a)bort     - exit Common Prolog
|?           - display this information
|
|? 
|
|In a little more detail...
|
|creep   - causes exhaustive tracing of the
|          next goal
|skip    - ignores spy points and executes
|          without displaying anything until
|          this goal is reached again 
|          either at an exit, fail, 
|          or redo port
|leap    - turns off exhaustive tracing until
|          a spy point or this goal is
|          reached
|break   - enters a recursive interpreter loop
|          so that the user may query
|          values, redefine a predicate, etc.
|display - uses "listing" to display the 
|          listing of the current goal
|quit    - returns to the top level interpreter
|         loop
|retry   - causes execution to return to the
|          call port of this goal as if
|           this goal had just been reached for
|          the first time. 
|fail    - causes execution to jump to the fail
|         port of this goal
|abort   - completely exit Common Prolog

Continuing the example:

|d <- user selects display
|
|Compiled procedure:
|
|(DEFREL MEMBER 
|  ((MEMBER ?X (?X . ?)))
|  ((MEMBER ?X (? . ?Y)) (MEMBER ?X ?Y))) ? c 
|  ...user selects creep
|[1] EXIT: (MEMBER 3 (3 . ?0))? r 
|  ...user selects retry
|
|[1] CALL: (MEMBER 3 ?0)? f <-user selects fail
|
|[1] FAIL: (MEMBER 3 ?0)? r <- one more time
|
|[1] CALL: (MEMBER 3 ?0)? s <- skip
|
|[1] EXIT: (MEMBER 3 (3 . ?0))? l <- leap
|?X = (3 . ?0); <- more solutions
|
|[1] REDO: (MEMBER 3 (3 . ?0))? c <- creep
|
|[2] CALL: (MEMBER 3 ?0)? b <- break
|
|
|==> (nospy)
|
|NIL <- current spylist
|YES.
|OK.
|
|==> (halt) <- return to original execution
|? l <- leap
|
|?X = (?0 3 . ?1)<cr>
|
|OK.

Another example:

|==> (defrel reverse
|      ((reverse () ()))
|      ((reverse (?x . ?y) ?z)
|       (reverse ?y ?w)
|       (append ?w (?x) ?z)))
|<noise..>
|
|?X = ?0
|?Y = ?1
|?Z = ?2
|?W = ?3
|
|OK.
|==> (defrel append
|      ((append () ?x ?x))
|      ((append (?u . ?x) ?y (?u . ?z))
|       (append ?x ?y ?z)))
|<noise..>
|?X = ?0
|?U = ?1
|?Y = ?2
|?Z = ?3
|
|OK.
|==> (unleash)
|
|YES.
|OK. 
|
|==> (trace)
|
|YES.
|OK. 
|==> (reverse (1 2 3) ?x)
|
|[1] CALL: (REVERSE (1 2 3) ?0)
|[2] CALL: (REVERSE (2 3) ?0)
|[3] CALL: (REVERSE (3) ?0)
|[4] CALL: (REVERSE NIL ?0)
|[4] EXIT: (REVERSE NIL NIL)
|[5] CALL: (APPEND NIL (3) ?0)
|[5] EXIT: (APPEND NIL (3) (3))
|[3] EXIT: (REVERSE (3) (3))
|[6] CALL: (APPEND (3) (2) ?0)
|[7] CALL: (APPEND NIL (2) ?0)
|[7] EXIT: (APPEND NIL (2) (2))
|[6] EXIT: (APPEND (3) (2) (3 2))
|[2] EXIT: (REVERSE (2 3) (3 2))
|[8] CALL: (APPEND (3 2) (1) ?0)
|[9] CALL: (APPEND (2) (1) ?0)
|[10] CALL: (APPEND NIL (1) ?0)
|[10] EXIT: (APPEND NIL (1) (1))
|[9] EXIT: (APPEND (2) (1) (2 1))
|[8] EXIT: (APPEND (3 2) (1) (3 2 1))
|[1] EXIT: (REVERSE (1 2 3) (3 2 1))
|?X = (3 2 1);
|[1] REDO: (REVERSE (1 2 3) (3 2 1))
|[8] REDO: (APPEND (3 2) (1) (3 2 1))
|[9] REDO: (APPEND (2) (1) (2 1))
|[10] REDO: (APPEND NIL (1) (1))
|[10] FAIL: (APPEND NIL (1) ?0)
|[9] FAIL: (APPEND (2) (1) ?0)
|[8] FAIL: (APPEND (3 2) (1) ?0)
|[2] REDO: (REVERSE (2 3) (3 2))
|[6] REDO: (APPEND (3) (2) (3 2))
|[7] REDO: (APPEND NIL (2) (2))
|[7] FAIL: (APPEND NIL (2) ?0)
|[6] FAIL: (APPEND (3) (2) ?0)
|[3] REDO: (REVERSE (3) (3))
|[5] REDO: (APPEND NIL (3) (3))
|[5] FAIL: (APPEND NIL (3) ?0)
|[4] REDO: (REVERSE NIL NIL)
|[4] FAIL: (REVERSE NIL ?0)
|[3] FAIL: (REVERSE (3) ?0)
|[2] FAIL: (REVERSE (2 3) ?0)
|[1] FAIL: (REVERSE (1 2 3) ?0)
|NO. 

KnowledgeWorks and Prolog User Guide (Windows version) - 24 Mar 2017

NextPrevUpTopContentsIndex