# 5 Environment Inspection

In this chapter you learn how to investigate the environment, i.e, how to access the values of variables. In fact, we must distinguish between two kinds of enviroments in Oz. First, there is the toplevel enviroment. Here you find all the variables which are defined right after you started the mozart system. The procedure `Show` is an example, the module `String` is another. Second, there exist environments for each stack frame (i.e. each called procedure) of a thread. They consist of local variables, which are the union of locally defined variables and formal parameters, and global variables, which are referenced inside the procedure, but defined outside.

Environment inspection is easy with Ozcar. In fact, it is done automatically for you. Whenever you select a stack frame, the variables which are visible inside this frame are printed in the variable windows. You can inspect the values by clicking on their type information.

## 5.1 The Query Dialog

There might be situations where you have to operate on some values which are found in the local or global environment. For example, you want to convert a data structure, or to bind an unbound variable which causes your program to hang.

For this purpose the query dialog exists. You can open it by selecting the Query... menu entry in the Stack menu.

### 5.1.1 Evaluation of Expressions

Using this dialog, you can evaluate arbitrary Oz expressions. For example, if you type

> `{fun {$ A B C} A+B*C end 1 2 3}`

in the Query line and press the Eval button, you get the expected result, `7`, in the Result line. Another example shows the following picture:

Picture 5.1: You can evaluate arbitrary expressions

### 5.1.2 Execution of Statements

Something other you can do with the Query dialog is to execute Oz statements. For example, when you type `{Inspect hugo}` and press the Exec button, the Inspector pops up and prints the obvious data. Note that the result of executing a statement is `unit`. Another example comes with the next picture. An unbound variable, `G2`, is bound to the value `7`. You would have to reprint the variable view's content (by reselecting the stack frame) in order to update its information.

Picture 5.2: You can execute all kinds of statements

You can open as many Query dialogs as you like. This makes it possible to evaluate several expressions more than one time without always re-entering them.