Example 1 <# i := 0; j := 10 #>
<# j := j - i++ #>
In Example 1, the result is that i equals 1 and j equals 10, because the expression is
evaluated (10 – 0 = 10) before i is incremented.
Example 2 <# i := 0; j := 10 #>
<# j := j - ++i #>
In Example 2, the result is still that i equals 1, but now j equals 9, because i is
incremented to 1 before the expression is evaluated (10 – 1 = 9).
Similarly, you can use the decrement operator (– –) to decrement local variables.
Placement of the operator has the same effect as for the increment operator.
When a local variable with a string value is used with the increment or decrement
operators, the value is permanently converted to an integer equal to the length in
characters of the string value.
String Operations
The combine operator ($) concatenates two strings into one longer string. Numeric
expressions are converted to strings before the operation proceeds. The variable
local evaluates to “ want a big” :
Example \<# local := “ want a ” $ “ big” #>
Extraction Operations
The extraction operations are substring (substr), randomize (rand), round, and
truncate. These operators are equal in precedence, and all take precedence over the
string operator.
You can use the substring operator (substr) to extract a shorter string from a longer
string. To use the substring operator, you must specify the source string, an offset
value, and a count value. You can specify the string directly, or you can specify a
local variable that contains the string. The offset value indicates the place of the first
character of the substring to be extracted; “ 0” indicates the first character in the
source string. The count value indicates the length of the substring. If the source
string has fewer characters than the sum of the offset and count values, then the
resulting substring has fewer characters than indicated by the count value.
Example <# local := “ want a ” $ “ big” $ “ string” #>
<# substr(local, 5, 12) #>The result is “ a big string”
<# substr(local, 0, 10) #>The result is “ want a big”
<# substr(“ ready” , 0, 4) #>The result is “ read”
The random operator produces a random integer value from the specified inclusive
range; in the following example, the result is between 1 and 10:
<# number:= rand(1,10) #>
The round operator rounds off the number to the nearest integer:
Writing Macros ■ 483
Chapter 8: Writing CLI Macros