The HMD software program is first a basic mathematics interactive workspace and script interpreter. As such, it is a mini programming language with syntax similar to the C language or like Scilab or Matlab. The advantage of an interactive workspace is that variables can be created and used in computations. Script files can be loaded and executed from the shell command line.
Code statements are in the form of an equation,
x = 1;
with standard C or XxxLab arithmetic operations. For example,
y = 2.5 * x / (x + 1);
Variables can be single numbers, that is, scalars, or variables can be arrays.
x = 2; // a scalar
x = [1, 2, 3] // an array
cx = <1 % 3>; // a complex number, 1 + 3i
Variables can be defined "on the fly," which is done in most scripting languages, or they may be declared with a certain type, like in C:
int iCount;
double dMagnitude[10];
If a variable is created on-the-fly it will automatically be of type double. In computations, the result will end up being of type double or doublecomplex, so the other data types have limited use. For example, the int and long types are useful for array indices or counters.
Access to arrays is performed like in C, with square brackets,
myvar = dMagnitude[3];
Calculations involving arrays are performed on every element of the array, like in the XxxLab languages,
newMagnitude = 5.0 * dMagnitude;
produces a new array which is dMagnitude multiplied by 5.
There are currently two kinds of redirection in an HMD script: the if / else construct and the while loop. An example of an if statement would be
if (x < 3) {
// some code
}
Notice that the code to be executed must be enclosed in curly brackets and that the opening bracket must be on the same line with the conditional test. Similarly, for a while loop,
x = 0;
while (x < 3) {
// some code
x = x + 1;
}
Function are defined with the function keyword, followed by the name, followed by a list of parameters enclosed in curly brackets, followed by an opening curly bracket, all on one line:
function My_Function { int count, double value } {
int cnt2;
// some code
return 3;
}