Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > d1f06a5336fd6bf4a381b72b8d2b5ce1 > files > 146

gprolog-1.2.16-3mdk.ppc.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14">
<TITLE>
 The procedure box model
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="manual010.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual009.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual012.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#66dbff"><DIV ALIGN=center><TABLE>
<TR><TD><FONT SIZE=4><B><A NAME="htoc21">4.2</A></B></FONT></TD>
<TD WIDTH="100%" ALIGN=center><FONT SIZE=4><B>The procedure box model</B></FONT></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
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 &amp;
Mellish&nbsp;[<CITE><A HREF="manual071.html#Clock">2</A></CITE>]. The debugger executes a program step by step tracing an
invocation to a predicate (<TT>call</TT>) and the return from this predicate
due to either a success (<TT>exit</TT>) or a failure (<TT>fail</TT>). When a
failure occurs the execution backtracks to the last predicate with an
alternative clause. The predicate is then re-invoked (<TT>redo</TT>).
Another source of change of the control flow is due to exceptions. When an
exception is raised from a predicate (<TT>exception</TT>) by
<TT>throw/1</TT> (section&nbsp;<A HREF="manual022.html#catch/3">6.2.4</A>) the control is given back to the most
recent predicate that has defined a handler to recover this exception using
<TT>catch/3</TT> (section&nbsp;<A HREF="manual022.html#catch/3">6.2.4</A>). The procedure box model shows these
different changes in the control flow, as illustrated here:<BR>
<DIV ALIGN=center><IMG SRC="debug-box.gif"></DIV><BR>
Each arrow corresponds to a <EM>port</EM>. 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 to subgoals. Finally, it should be clear that a
box is associated to 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 to each box a unique
identifier (i.e. the invocation number). <BR>
<BR>

<HR SIZE=2>
Copyright (C) 1999-2002 Daniel Diaz
<BR>
<BR>
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved. <BR>
<BR>
<A HREF="index.html#copyright">More about the copyright</A>
<HR>
<A HREF="manual010.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual009.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual012.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>