Programming 243
into the same local variable, this is poor programming
practice and should be avoided.
Qualifying the
name of a
variable
The HP39gII system has many system variables with
names that are apparently the same. For example, the
Function app has a variable named Xmin, but so, too, do
the Polar, Parametric, Sequence, and Solve apps. In a
program, or in the Home view, you can reference
different versions of these by fully "qualifying" the name
of the variable. This is done by inserting the name of the
app (or program) that the variable belongs to, followed
by two colons, and then the actual variable name. For
example, the qualified variables Function::Xmin and
Parametric::Xmin refer to the value of Xmin within
each app, and could contain different values. Similarly,
if you declare a local variable inside a program, you
could reference that variable using the name of the
program, followed by the two colons and the variable
name.
Variables declared in a program should have descriptive
names. For example, a variable used to store the radius
of a circle can be named RADIUS. If such a variable is
needed after the program executes, it can be exported
from the program using the EXPORT command. To do
this, the first command in the program (located before the
program heading) would be EXPORT RADIUS. Then, if
a value is assigned to RADIUS, the name would appear
on the Vars menu and be visible globally. This feature
allows for extensive and powerful interactivity among
different environments in the HP39gII. Note that if more
than one program exports a variable with the same
name, the most recently exported version will be active,
unless the name is fully qualified.
This program prompts the user for the value of RADIUS,
and exports the variable for use outside the program.
EXPORT RADIUS;
EXPORT GETRADIUS()
BEGIN
INPUT(RADIUS);
END;