Special variables -- $TEST

$T[EST]

Introduced in the 1977 ANSI M[UMPS] language standard.

The value of this variable identifies whether or not the most recent occurrence of one of the following commands was successful: IF (always), READ (with time-out), OPEN (with time-out) or LOCK (with time-out).

IF DEVICE'=PRINTER OPEN DEVICE::20
ELSE OPEN PRINTER:120

When the values of the variables DEVICE and PRINTER are unequal and opening the device indicated by DEVICE can not be realized within 20 seconds, the value of $TEST becomes 0 (false) and the device indicated by PRINTER will be opened as soon as it is available. Note that the ::20 specifies a timeout and the :120 specifies an implementation-specific deviceparameter.
When the values of DEVICE and PRINTER are equal, the device indicated by PRINTER will be opened as soon as it is available.
Note that the action taken after the ELSE command depends on the outcome of the IF command, but also on the outcome of the timeout when it is processed.

Additions in a future ANSI M[UMPS] language standard:

The special variable $TEST may occur as an argument of the NEW command.

 SET T="$TEST should be "
 IF REASON DO SUB1 WRITE !,T,"1:",$TEST,"."
 ELSE  DO SUB2 WRITE !,T,"1: ",$TEST,"."
 QUIT
SUB1 WRITE !,T,"1: ",$TEST,"."
 NEW $TEST
 IF 0 ; Force $TEST to a new value
 QUIT
SUB2 WRITE !,T,"0: ",$TEST,"."
 IF 1 ; Force $TEST to a new value
 QUIT

The initial value of $TEST is 0 (false).

The THEN command may be used to stack the value of $TEST "until the end of the current line".

Assume that the code segment below is executed.

 FOR A=1,0 DO
 . IF A WRITE !,"TRUE 1" IF 0
 . ELSE  WRITE !,"FALSE 1"
 . IF A THEN  WRITE !,"TRUE 2" IF 0
 . ELSE  WRITE !,"FALSE 2"
 . QUIT

At the first iteration of the FOR loop, the value of A is true (1). The first IF command will cause the text "TRUE 1" to be written, and the second IF command on that line will cause the value of special variable $TEST to be set to 0 (false). As a result, on the next line, the ELSE command will cause the text "FALSE 1" to be written.

The next IF command will cause the text "TRUE 2" to be written, and this time, the THEN command will stack the value of $TEST (which is at this point equal to 1). After this, the second IF command on that line will cause the value of special variable $TEST to be set to 0 (false). At this point, the end of the line is reached, and the value of $TEST will be popped off the stack, setting it back to 1 (true). As a result, on the next line, the ELSE command will cause the rest of that line to be ignored.

At the second iteration of the FOR loop, the value of A is false (0). The first IF command will cause the rest of that line to be ignored, and, on the next line, the ELSE command will cause the text "FALSE 1" to be written.

The next IF command will also cause the rest of that line to be ignored, and, on the next line, the ELSE command will cause the text "FALSE 2" to be written.


This document is © Ed de Moel, 1995-2005.
It is part of a book by Ed de Moel that is published under the title "M[UMPS] by Example" (ISBN 0-918118-42-5).
Printed copies of the book are no longer available.

This document describes the various special variables that are defined in the M[UMPS] language standard (ANSI X11.1, ISO 11756).

The information in this document is NOT authoritative and subject to be modified at any moment.
Please consult the appropriate (draft) language standard for an authoritative definition.

In this document, information is included that will appear in future standards.
The MDC cannot guarantee that these 'next' standards will indeed appear.