Setting Variables

Home, Up: Variables and User-Defined Constants

 

On this page:

Variable Names, Creating a Variable, The $myvar = Assign Command, The STO Command, Viewing Variables, Deleting a Variable.

 

Variable Names

The name of a variable must begin with the dollar sign $. Hypatia assumes anything that begins with $ to be a variable.

Variable names can not contain spaces.

Since anything you type (apart from comments) is converted to lower case, variable names are case insensitive.

The variables $loop and $zero have special meanings, do not use them except for their intended purposes.

$ and $$ are pseudo variables (see Chain Calculations, $ and $$), you cannot assign values to them as described below.

 

Creating a Variable

$myvar stands here for any variable name you may want to use.

You create a variable by assigning it a value. This can be done in three ways:

- The assign command $myvar = followed by a number, a constant, another variable, or a mathematical expression.

- The STO $myvar command.

- The PROMPT $myvar command, but for this we have to wait until the chapter "Scripts".

 

At any time you can assign a different value to the variable -- that's their purpose, after all.

There is no limit to the numbers of variables you may use.

Hypatia forgets the variables when you close the program, but you can save them -- see the next page.

 

The $myvar = Assign Command

This is the method you will probably want to use -- the variable name, followed by an equal sign, followed by anything that amounts to a single numerical value.

There must be a space before and after the eqal sign!

Note that, even though the part after the equal sign gets calculated, $myvar = is a command, which for instance means that the recent calculation result $ is not updated!

Unlike other commands, though, the $myvar = line gets written to the file hyin.

Examples:

 

$length = 7.5

$area = $length SQ

$n = $n 1 +

 

Anything that would be a valid calculation line can stand to the right of the equal sign.

If the variable already has a value, you can use DUP after the equal sign to represent this value:

 

$myvar = $DUP 1 +

is the same as

$myvar = $myvar 1 +

 

The STO Command

STO $myvar stores the recent calculation result (the value of the pseudo variable $) in the variable $myvar.

You could do the same by entering $myvar = $ -- the STO command mostly exists for historic reasons, but you may still find it useful.

 

Viewing Variables

SHOW shows the values of all currently defined variables, including $ and $$.

SHOW $myvar shows the value of variable $myvar.

In case that you have set angle unit to degrees (default is radians) a respective note will be displayed, since some values might be angles.

You can list more than one variable after the SHOW command:

SHOW $var1 $var2 $var3 etc.

(The list of variables to show can include the loop index I and the loop timer TIME, see chapter "Loops".)

 

Deleting a Variable

DEL $myvar deletes the variable $myvar.

Note that the command DEL can only delete a single variable at a time.

 

Home, Up: Variables and User-Defined Constants, Next: Saving Variables