If you perform an operation or comparison between a character string and a number, DCL converts the character string to a number.
String operands can be added (string concatenation), subtracted (string reduction), compared, or replaced with other character strings as described in the following subsections.
$ TEMP = "CAT"
$ TOPIC = "THE" + TEMP
$ COUNT = F$STRING(65)
You can specify the following character string operations:
$ COLOR = "light brown" $ WEIGHT = "30 lbs." $ DOG2 = "No tag, " + COLOR + ", " + WEIGHT $ SHOW SYMBOL DOG2 DOG2 = "No tag, light brown, 30 lbs."
$ SHOW SYMBOL DOG2 DOG2 = "No tag, light brown, 30 lbs." $ DOG2 = DOG2 - ", 30 lbs." $ SHOW SYMBOL DOG2 DOG2 = "No tag, light brown"
When you compare two character strings, the strings are compared character by character. Strings of different lengths are not equal (for example, "dogs" is greater than "dog").
The comparison criteria are the ASCII values of the characters. Under these criteria, the digits 0 to 9 are less than the uppercase letters A to Z, and the uppercase letters A to Z are less than the lowercase letters a to z. A character string comparison ends when either of the following conditions is true:
Table 14-1 lists different types of string comparisons.
Comparison | Operator | Description |
---|---|---|
Equal to | .EQS. | Compares one character string to another for equality. |
Greater than or equal to | .GES. | Compares one character string to another for greater or equal value in the first specified string. |
Greater than | .GTS. | Compares one character string to another for a greater value in the first specified string. |
Less than or equal to | .LES. | Compares one character string to another for a lesser or equal value in the first specified string. |
Less than | .LTS. | Compares one character string to another for a lesser value in the first specified string. |
Not equal | .NES. | Compares one character string to another for inequality. |
In all of these examples, assume that the symbol LAST_NAME has the value "WHITFIELD".
$ TEST_NAME = LAST_NAME .EQS. "Hill" $ SHOW SYMBOL TEST_NAME TEST_NAME = 0 ...
$ TEST_NAME = LAST_NAME .GES. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 1 ...
$ TEST_NAME = LAST_NAME .GTS. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 1 ...
$ TEST_NAME = LAST_NAME .LES. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 0 ...
$ TEST_NAME = LAST_NAME .LTS. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 0 ...
$ TEST_NAME = LAST_NAME .NES. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 1 ...
You can replace part of a character string with another character string by specifying the position and size of the replacement string. The format for local symbols is:
symbol-name[offset,size] := replacement-string
The format for global symbols is:
symbol-name[offset,size] :== replacement-string
The elements are as follows:
offset | An integer that indicates the position of the replacement string relative to the first character in the original string. An offset of 0 means the first character in the symbol, an offset of 1 means the second character, and so on. |
size | An integer that indicates the length of the replacement string. |
To replace substrings, observe the following rules:
Lining up records in columns makes a list easier to read and sort. You can use this format to specify how you want data to be stored.
$ A := PACKRAT $ A[0,4] := MUSK $ SHOW SYMBOL A A = "MUSKRAT"
$ B[4,3] := RAT
$ LINE[0,80]:= " "
$ DATA[0,15] := 'NAME' $ DATA[17,1] := 'GRADE'
A number can have the following values:
The number you assign to a symbol must be in the range --2147483648 to 2147483647 (decimal). An error is not reported if a number outside this range is specified or calculated but an incorrect value results.
At DCL command level and within command procedures, specify a number as follows:
$ DOG_COUNT = 13 $ SHOW SYMBOL DOG_COUNT DOG_COUNT = 13 Hex = 0000000D Octal = 00000000015
$ BALANCE = -15237 $ SHOW SYMBOL BALANCE BALANCE = -15237 Hex = FFFFC47B Octal = 37777742173
$ DOG_COUNT = %XD $ SHOW SYMBOL DOG_COUNT DOG_COUNT = 13 Hex = 0000000D Octal = 00000000015 $ BALANCE = -%X3B85 $ SHOW SYMBOL BALANCE BALANCE = -15237 Hex = FFFFC47B Octal = 37777742173
Numbers are stored internally as signed 4-byte integers, called longwords; positive numbers have values of 0 to 2147483647 and negative numbers have values of 4294967296 minus the absolute value of the number. The number -15237 , for example, is stored as 4294952059. Negative numbers are converted back to minus-sign format for ASCII or decimal displays; however, they are not converted back for hexadecimal and octal displays. For example, the number -15237 appears in displays as hexadecimal FFFFC47B (decimal 4294952059) rather than hexadecimal --00003B85.
Numbers are stored in text files as a series of digits using ASCII conventions (for example, the digit 1 has a storage value of 49).
In a numeric expression, the values involved must be literal numbers (such as 3) or symbols with numeric values. In addition, you can use a character string that represents a number (for example, "23" or " -51 "). If you perform an operation or comparison between a number and a character string, DCL converts the character string to a number.
Numeric expressions combine the following values (called integer operands):
$ COUNT = 1
$ B = F$INTEGER("-9" + 23)
$ A = B - 6
These integer operands can be connected by arithmetic, logical, and comparison operators, as described in the following sections.
You can specify the following arithmetic operations:
$ BALANCE = 142 * 14 $ SHOW SYMBOL BALANCE BALANCE = 1988 Hex = 000007C4 Octal = 00000003704
$ BALANCE = BALANCE / 14 $ SHOW SYMBOL BALANCE BALANCE = 142 Hex = 0000008E Octal = 00000000216
$ BALANCE = BALANCE + 37 $ SHOW SYMBOL BALANCE BALANCE = 179 Hex = 000000B3 Octal = 00000000263
$ BALANCE = BALANCE - 15416 $ SHOW SYMBOL BALANCE BALANCE = -15237 Hex = FFFFC47B Octal = 00000142173
$ BALANCE = -(- a142) $ SHOW SYMBOL BALANCE BALANCE = 142 Hex = 0000008E Octal = 00000000216
Table 14-2 lists different types of numeric comparisons:
Comparison | Operator | Description |
---|---|---|
Equal to | .EQ. | Compares one number to another for equality. |
Greater than or equal to | .GE. | Compares one number to another for a greater or equal value in the first number. |
Greater than | .GT. | Compares one number to another for a greater value in the first number. |
Less than or equal to | .LE. | Compares one number to another for a lesser or equal value in the first number. |
Less than | .LT. | Compares one number to another for a lesser value in the first number. |
Not equal to | .NE. | Compares one number to another for inequality. |
In the following examples, assume that the symbol BALANCE has the value -15237 .
$ TEST_BALANCE = BALANCE .EQ. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 1 ...
$ TEST_BALANCE = BALANCE .GE. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 1 ...
$ TEST_BALANCE = BALANCE .GT. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 0 ...
$ TEST_BALANCE = BALANCE .LE. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 1 ...
$ TEST_BALANCE = BALANCE .LT. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 0 ...
$ TEST_BALANCE = BALANCE .NE. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 0 ...
You can perform binary (bit-level) overlays of the current symbol value by using a special format of the assignment statement. For local symbols, the format is:
symbol-name[bit-position,size] = replacement-expression
For global symbols, the format is:
symbol-name[bit-position,size] == replacement-expression
The elements are as follows:
bit-position | An integer that indicates the location relative to bit 0 at which the overlay is to occur. |
size | An integer that indicates the number of bits to be overlaid. |
To use numeric overlays, observe the following rules:
The following example defines the symbol BELL as the value 7. The low-order byte of BELL has the binary value 00000111. By changing the 0 at offset 5 to 1 (beginning with 0, count bits from right to left), you create the binary value 00100111 (decimal value 39):
$ BELL = 7 $ BELL[5,1] = 1 $ SHOW SYMBOL BELL BELL = 39 Hex = 00000027 Octal = 00000000047
The following sections describe how to use logical values and expressions.
Some operations interpret numbers and character strings as logical data with values as follows:
In the following examples, DOG_COUNT is assigned the value 13. IF STATUS means if the logical value of STATUS is true.
$ STATUS = 1 $ IF STATUS THEN DOG_COUNT = 13
$ STATUS = "TRUE" $ IF STATUS THEN DOG_COUNT = 13
A logical operation affects all the bits in the number being acted upon. The values for logical expressions are integers, and the result of the expression is an integer as well. If you specify a character string value in a logical expression, the string is converted to an integer before the expression is evaluated.
Typically, you use logical expressions to evaluate the low-order bit of a logical value; that is, to determine whether the value is true or false. You can specify the following logical operations:
Bit Level | Entity Level |
---|---|
1 .AND. 1 = 1 | true .AND. true = true |
1 .AND. 0 = 0 | true .AND. false = false |
0 .AND. 1 = 0 | false .AND. true = false |
0 .AND. 0 = 0 | false .AND. false = false |
Bit Level | Entity Level |
---|---|
1 .OR. 1 = 1 | true .OR. true = true |
1 .OR. 0 = 1 | true .OR. false = true |
0 .OR. 1 = 1 | false .OR. true = true |
0 .OR. 0 = 0 | false .OR. false = false |
$ SHOW SYMBOL STATUS STATUS = 1 Hex = 00000001 Octal = 00000000001 $ STATUS = .NOT. STATUS $ SHOW SYMBOL STATUS STATUS = -2 Hex = FFFFFFFE Octal = 37777777776
$ STAT1 = "TRUE" $ STAT2 = "FALSE" $ STATUS = STAT1 .AND. STAT2 $ SHOW SYMBOL STATUS STATUS = 0 Hex = 00000000 Octal = 00000000000
$ STAT1 = "TRUE" $ STAT2 = "FALSE" $ STATUS = STAT1 .OR. STAT2 $ SHOW SYMBOL STATUS STATUS = 1 Hex = 00000001 Octal = 00000000001
The following tables demonstrate the results of logical operations on a bit-by-bit basis and a number-by-number basis. In logical operations, a character string beginning with an uppercase or lowercase T or Y is treated as the number 1; a character string beginning with any other character is treated as the number 0. In logical operations, odd numbers are true and even numbers and zero are false.
Given That: | The Results Are: | ||||
---|---|---|---|---|---|
Bit A | Bit B | .NOT. A | A .AND. B | A .OR. B | |
1 | 1 | 0 | 1 | 1 | |
1 | 0 | 0 | 0 | 1 | |
0 | 1 | 1 | 0 | 1 | |
0 | 0 | 1 | 0 | 0 |
Given That: | The Results Are: | ||||
---|---|---|---|---|---|
Number A | Number B | .NOT. A | A .AND. B | A .OR. B | |
odd | odd | even | odd | odd | |
odd | even | even | even | odd | |
even | odd | odd | even | odd | |
even | even | odd | even | even |
Typically used in command procedures, lexical functions retrieve information from the system, including information about system processes, batch and print queues, and user processes. You can also use lexical functions to manipulate character strings and translate logical names. When you assign a lexical function to a symbol, the symbol is equated to the information returned by the lexical function (for example, a number or character string). At DCL level, you can then display that information with the DCL command SHOW SYMBOL. In a command procedure, the information stored in the symbol can be used later in the procedure. See the Chapter 17 for additional information on lexical functions.
To use a lexical function, specify the name of the lexical function (which always begins with F$) and its argument list. Use the following format:
F$function-name(args[,...])
The argument list follows the function name with any number of intervening spaces and tabs.
When you use a lexical function, observe the following rules:
Use lexical functions the same way you would use character strings, integers, and symbols. When you use a lexical function in an expression, DCL automatically evaluates the function and replaces the function with its return value.
In the following example, the F$LENGTH function returns the length of the value specified as BUMBLEBEE as its argument. DCL automatically determines the return value (9) and uses this value to evaluate the expression. Therefore, the result of the expression (9 + 1) is 10 and this value is assigned to the symbol SUM:
$ SUM = F$LENGTH("BUMBLEBEE") + 1 $ SHOW SYMBOL SUM SUM = 10 Hex = 0000000A Octal = 00000000012
Note that each lexical function returns information as either an integer or a character string. In addition, you must specify the arguments for a lexical function as either integer or character string expressions.
6489P024.HTM OSSG Documentation 22-NOV-1996 13:17:12.02
Copyright © Digital Equipment Corporation 1996. All Rights Reserved.