Using Variables

Revised: 10/28/07

Most parameters in routines can take their values from variables. Writing a program to use variables generally makes it more flexible and much easier to use. For example, in working with single neurons you might use a series of programs to characterize different aspects of a cell's behavior (contrast-response relationship, chromatic properties, etc.), and in such cases you would often want to use gratings of the optimal orientation and spatial frequency. If all the programs take their spatial frequency and orientation settings from the same variables, you need set these values only once for each cell.

Expo maintains a set of global variables, each of which is created and typed by its first appearance in a program. A global variable can be used by any routine parameter in any open program, providing the type of the variable matches the type of the parameter (variables of "Any" type are special: they can be used without restriction). Expo also provides local variables, with scope confined to a single instance of a state or matrix substate in a slot. (If a state appears in multiple slots in the schedule, each instance has its own set of local variables.) Local variables are used to pass parameter values between routines in that instance of the state, and are invisible outside it. A global or local variable is created (if it doesn't already exist) when you first name it in a program you are writing, or when you load an existing program that names it. Expo distinguishes local and global variables by their names: local variables can (must) have names that begin with $; global variables can have any names that begin neither with $ nor a numeral. Expo defines two special read-only local variables that are always available to a program:

$pass holds a count of the number of times the scheduler has passed through the state/slot currently running.

$elapsed holds the time for which the slot currently running has been active.

Variables Window

You manage global variables (track and change their values, change the units in which they are represented, purge them) through a window that you open by choosing Environment->Variables (Command-B). The window can display up to twenty variables.

When you first open the Variables window it displays all the variables currently used by the front most program. You can display any other group by choosing it from the Show menu. (You can also display the variables used by any program by Option double-clicking the program's Status window.) Click Active to view the group of variables used by the running program. If that group of variables is already on display, or no program is running, the button is dimmed. In the Show menu the running program is always identified by a red bullet beside its name; a suspended program is identified by an orange bullet.

To show windows for the program currently selected, double-click the Show prompt beside the popup menu.

Although Expo places no limits on the numbers of global variables you can use in a program, it can display no more than 20 global variables in the Variables window.

Expo never displays local variables, and you cannot directly assign values to them. Within a state you can assign a value to a local variable by making it the destination of a routine's output parameter, and you can use a routine such as Op Variable or If… Else… to pass values between local and global variables.

When you close a program that uses variables, Expo does not normally expunge them. To purge variables that are used by no open program, click Purge.

To clear all saved values of variables, Option-click Purge.

When you quit Expo it saves the values of all global variables that have been defined by open programs. When you start a new session and open any programs that use variables whose values have previously been saved, these values are restored.

Setting Values and Units

When a global variable is first used Expo automatically initializes it to its last-saved value, or (if it has never been used) to the default value of the routine parameter in which it was first called. For a parameter that writes to a variable rather than reads from it, Expo defines no default value with which to initialize the variable, so it is initialized to NaN. Local variables are automatically initialized each time a program starts running (to the default values of the parameters in which they were first called if used as input; otherwise to NaN).

You can set the value of any displayed variable either with its slider or by typing directly into the text box beside it. Expo sets the range of the slider to cover the range of permissible values (minimum at the left, maximum at the right). The range is determined by the range allowed for the parameter that first used the variable or retyped it. Clicking on the slider moves 10% of the range. (An easy way to find the range of acceptable values for a variable is to move the slider from one limit to the other.) The current value is always displayed in the text box to the right of the slider.

If you type a value in the text box, complete the entry by hitting TAB or RETURN (your setting will be completed automatically if you change the displayed set or start a program). When you set the variable by typing a value, Expo may need to alter it slightly if the number you entered cannot be represented internally. The type of the variable determines whether or not Expo may adjust the number. For example, a temporal frequency can be generated accurately only if its period is an integral number of ticks, so the period in ticks is the fundamental unit in which temporal frequency is represented, and this is always an integer. When you type a value Expo checks that it is within the acceptable range, and that, if necessary, it can be represented exactly in the fundamental unit of the variable. If it cannot be represented exactly in its fundamental unit, Expo converts the number to the nearest value that can be represented exactly.

You can set the value of one variable directly from another that uses commensurate units. To do this, Control-click on the name of the variable you want to set. Expo will display a contextual menu. Choose from the Value from submenu the name of the variable that is to be the source of the value transferred.

The values of most variables can be represented in several different units. The possible units for any variable are displayed in the pop-up menu to the right of the box in which you can type its value. You can change the unit in which the value is expressed by choosing the one you want from the pop-up menu (the first unit in the menu is the fundamental unit in which the value is held). Changing the unit of expression does not alter the value of the variable.

Although there are no restrictions on where you can use a variable whose value is in "Any" units, you may sometimes want to manipulate its value in units appropriate for a particular routine parameter that uses it. To facilitate this, Expo allows you to change the base unit of a variable that has been defined as using "Any" units. To change the base unit, Control-click the name of the variable. Expo will display a contextual menu. Use the Type from submenu to choose another variable whose unit you want the variable to adopt.

When Expo is running a program it reads the values of relevant variables continuously. If you change the value of a variable that the program reads, the new value is made available immediately to the routine that uses the variable. If the program is writing values to any variable that is on view, the display will reflect the changes (the slider will move and the value in the text box will change). This provides one way track what is happening in a running program.

Appendix B provides more information about the internal organization of variables.

Finding and Replacing Variables in Programs

You can find which programs use a particular global variable and you can replace calls to one variable with calls to another one. You might need to change variables within a program to ensure consistent use across multiple programs.

To inspect or change the use of variables choose Edit->Replace Variables… Expo will display the following window:

To find which programs use a particular variable, choose the variable from the Find popop menu. Expo will display in the table the names of all the open programs that use the variable.

To replace a variable with another (either an existing variable or a new one) select in the table the programs in which you want to make the replacement, then at Replace with: type (or choose from the drop-down list) the name of the replacement variable. The drop-down list contains the names of all existing variables that are of the same type as the one being changed. Click Change to make the change.

You cannot replace a global variable with a constant or a local variable or another global variable of incommensurate type.