NairnFEAMPM Icon

Variables and Expressions

You can define variables in command files and do calculations on variables with expressions. Any argument to a command can be a variable or an expression.

Defining Variables

Variables are defined and used in the form #varname. Although not required, it is recommended that all variables begin in a number sign. This character is used to color code variables in commands and a couple of commands that take variable name itself as input require a number sign (or use it to distinguish it from object names). Beside that recommendation, the rules for a valid variable name:

A variable is initially defined in an assignment statement such as:

#x=1

where the variable is set equal to the right side of the equals sign which can be any valid expression.

Variable Arrays

Any valid variable can be a variable array by following it with an expression in square brackets

#y[#j]=1

where

Expressions

An expression combines any number of numbers, strings, variables, and functions with operators. An expression evaluates to a numeric or string value. The general, recursive definition of an expression is

[EXPRESSION] = [sign] [ATOMIC] [op] [ATOMIC] [op] [ATOMIC] ... [op] [ATOMIC]

where

Notes

  1. An assignment command can be combined with an operator as in
    #x [op] = [EXPRESSION]
    
    which is equivalent to
    #x = #x [op] ([EXPRESSION])
    
    provided the variable is already a defined variable. It is an error if the variable has not previously been defined.
  2. To omit first subargument in chars(), offset(), or replace(), start with a back slash (e.g., chars(\c2\string)). To omit second argument, you can either omit it and its backslash (e.g., chars(c1\string)), but if string might contain a backslash, it is better to just omit the subargument (e.g., chars(c1\\string)).