Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 1579

mozart-1.4.0-1mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>6 Environments</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node5.html#chapter.control">&lt;&lt; Prev</A></TD><TD><A href="index.html">- Up -</A></TD><TD><A href="node7.html#chapter.exceptions">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="chapter.data"><H1><A name="chapter.data">6 Environments</A></H1><P> In this chapter we'll learn how to examine and use the environment, i.&nbsp;e., how to access the values of variables. In fact, we need to distinguish between different kinds of environments. First, there is the toplevel environment. This is the environment relative to which code was compiled (in the case of <CODE>ozc</CODE>, this normally is the Base Environment defined in <A href="../base/index.html">``The Oz Base Environment''</A>). The procedure <CODE>NewName</CODE> is one example, the module <CODE>String</CODE> is another. Then there exist environments for each procedure (and accordingly, for each frame of a thread's stack). For one there is a procedure's global environment, which contains variables referenced within the procedure, but defined outside it (i.&nbsp;e., global to the procedure); for the purpose of debugging, we consider this to not contain all toplevel variables since they are always visible. Finally, there come the procedure's local variables, which include its formal parameters. </P><H2><A name="label23">6.1 Inspecting the Environment</A></H2><P> Environment inspection is easy with Ozcar. In fact, it is done automatically for you. Whenever you select a stack frame, the variables visible at the program point corresponding to this frame are displayed in the Environment Views. You can further examine the values using the Inspector by clicking on them. </P><H2><A name="label24">6.2 Using Values</A></H2><P> Ozcar allows you to access the value you have last clicked to inspect it. It can be requested by the expression </P><BLOCKQUOTE class="code"><CODE>{Ozcar<SPAN class="keyword">.</SPAN>object&nbsp;lastClickedValue($)}</CODE></BLOCKQUOTE><P> </P><H2><A name="label25">6.3 Compiling against the Environment</A></H2><P> There are situations where you want to operate on the values found in the local or global environment, for example, to convert a data structure, or to bind a logic variable which causes your program to hang. In these cases, you can use the Query dialog, opened by selecting the <CODE>Query </CODE>... entry in the <CODE>Stack</CODE> menu. </P><DIV class="apropos"><P class="margin">Evaluating Expressions</P><P> Using the Query dialog, you can evaluate arbitrary Oz expressions in the environment of the selected stack frame. Just enter the expression to evaluate on the <CODE>Query</CODE> line and press the <CODE>Eval</CODE> button to make the result appear on the <CODE>Result</CODE> line. <A href="node6.html#picture.eval-expression">Picture&nbsp;6.1</A> shows an example. </P><DIV class="picture" id="picture.eval-expression"><HR><P><A name="picture.eval-expression"></A></P><P></P><DIV align="center"><IMG alt="" src="eval-expression.gif"></DIV><P> </P><P class="caption"><STRONG>Picture&nbsp;6.1:</STRONG> Evaluating Arbitrary Expressions</P><HR></DIV><P> </P></DIV><DIV class="apropos"><P class="margin">Executing Statements</P><P> Besides evaluating expressions, the Query dialog allows to execute statements using the <CODE>Exec</CODE> button. The result of executing a statement will always be <CODE><SPAN class="keyword">unit</SPAN></CODE>. <A href="node6.html#picture.exec-statement">Picture&nbsp;6.2</A> shows an example scenario: An unbound variable, <CODE>G2</CODE>, is bound to the value <CODE>7</CODE>. (Note that the Environment Views are only updated when the stack frame is selected again.) </P><DIV class="picture" id="picture.exec-statement"><HR><P><A name="picture.exec-statement"></A></P><P></P><DIV align="center"><IMG alt="" src="exec-statement.gif"></DIV><P> </P><P class="caption"><STRONG>Picture&nbsp;6.2:</STRONG> Executing Statements</P><HR></DIV><P> </P></DIV><DIV class="apropos"><P class="margin">Compilation Environment</P><P> The exact environment used for compiling the code in the <CODE>Query</CODE> line is the currently active toplevel environment of the OPI (or the full default OPI environment when running standalone). Over this the selected frame's global environment is adjoined, and again the local environment is adjoined. Since the exact toplevel environment relative to which the code currently being debugged has been compiled is not available, this may be an incorrect approximation. Note also that the environment is constructed using the frame selected at the time the <CODE>Eval</CODE> or <CODE>Exec</CODE> button is pressed, not when the Query dialog is opened. </P></DIV><DIV class="apropos"><P class="margin">Multiple Queries</P><P> You can have as many Query dialogs as you like. This makes it possible to evaluate multiple pieces of code more than once without retyping them. </P></DIV></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node5.html#chapter.control">&lt;&lt; Prev</A></TD><TD><A href="index.html">- Up -</A></TD><TD><A href="node7.html#chapter.exceptions">Next &gt;&gt;</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~lorenz/">Benjamin&nbsp;Lorenz</A> and&nbsp;<A href="http://www.ps.uni-sb.de/~kornstae/">Leif&nbsp;Kornstaedt</A><BR><SPAN class="version">Version 1.4.0 (20090610)</SPAN></ADDRESS></BODY></HTML>