Home, Up: Variables and User-Defined Constants
On this page:
Hypatia's Variables, Variable Names, Creating a Variable, The $myvar = Assign Command, The STO Command, The SHOW Command, Deleting a Variable.
In all calculations variables can be used in place of numbers.
Hypatia's variables do not get declared before you use them, you create a variable by assigning it a value (see below).
Hypatia does not distinguish between integer or floating point variables, any variable can have any value.
A variable always has a single numerical value. Variables cannot be undefined, and variables cannot be arrays.
(Hypatia does know objects that can contain sequences, which come close to being one-dimensional arrays, they are called user-defined elements -- see page User-Defined Elements in chapter "Insert Files and User Defined Elements".)
All variables are lost when you close Hypatia or give the RESET command, but you can save variables and later retrieve them -- see the next page.
The name of a variable must begin with the dollar sign $. Hypatia assumes anything that begins with $ to be a variable.
Variable names cannot contain spaces.
Since anything you type (apart from comments) is converted to lower case, variable names are case insensitive -- $a is the same variable as $A.
The variables $loop and $zero have special meanings, do not use them except for their intended purposes.
$ and $$ are pseudo variables (see page Chain Calculations, $ and $$ in chapter "First Steps"), you cannot assign values to them as described below.
$myvar stands here for any variable name that 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 or pseudo constant, another variable, or an arithmetic expression combining any of them.
- The STO $myvar command.
- The PROMPT $myvar command, but for this we have to wait until we get to the chapter Scripts.
At any time you can assign a different value to a variable -- that's their main purpose, after all.
There is no limit to the numbers of variables you may use.
This is the method you will probably use most often -- 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 and not a calculation, which 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 -- the following two lines do the same:
$myvariable = $myvariable 1 +
$myvariable = $DUP 1 +
STO $myvar stores the recent calculation result (the value of the pseudo variable $) in the variable $myvar, creating the variable if it doesn't already exist.
You could do the same with the line $myvar = $ -- the STO command mostly exists for historic reasons, but you may still find it useful.
SHOW shows the values of all currently defined variables, including $ and $$.
SHOW $myvar shows the value of the variable $myvar.
You can list more than one variable after the SHOW command:
SHOW $var1 $var2 $var3 ...
You can use SHOW also with the loop index I and the loop timer TIME -- see page Pseudo Constants in chapter "Operators and Constants".
In case that you have set angle unit to degrees (default is radians) SHOW will display a note to this regard, since some values might be angles.
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