4.2 The procedure box model
The procedure box model of Prolog execution provides a simple way to show
the control flow. This model is very popular and has been adopted in many
Prolog systems (e.g. SICStus Prolog, Quintus Prolog,...). A good
introduction is the chapter 8 of “Programming in Prolog” of Clocksin &
Mellish [2]. The debugger executes a program step by step tracing an
invocation to a predicate (call) and the return from this predicate
due to either a success (exit) or a failure (fail). When a
failure occurs the execution backtracks to the last predicate with an
alternative clause. The predicate is then re-invoked (redo).
Another source of change of the control flow is due to exceptions. When an
exception is raised from a predicate (exception) by
throw/1 (section 6.2.4) the control is given back to the most
recent predicate that has defined a handler to recover this exception using
catch/3 (section 6.2.4). The procedure box model shows these
different changes in the control flow, as illustrated here:
Each arrow corresponds to a port. An arrow to the box indicates
that the control is given to this predicate while an arrow from the box
indicates that the control is given back from the procedure. This model
visualizes the control flow through these five ports and the connections
between the boxes associated with subgoals. Finally, it should be clear that a
box is associated with one invocation of a given predicate. In particular, a
recursive predicate will give raise to a box for each invocation of the
predicate with different entries/exits in the control flow. Since this might
get confusing for the user, the debugger associates with each box a unique
identifier (i.e. the invocation number).
Copyright (C) 1999-2007 Daniel Diaz
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved.
More about the copyright