Product SiteDocumentation Site

Chapter 17. Special Variables

A special variable can be set automatically during processing of a Rexx program. There are five special variables:
RC
is set to the return code from any executed command (including those submitted with the ADDRESS instruction). After the trapping of ERROR or FAILURE conditions, it is also set to the command return code. When the SYNTAX condition is trapped, RC is set to the syntax error number (1-99). RC is unchanged when any other condition is trapped.

Note

Commands executed manually during interactive tracing do not change the value of RC.
RESULT
is set by a RETURN instruction in a subroutine that has been called, or a method that was activated by a message instruction, if the RETURN instruction specifies an expression. (See Section 2.6, “EXIT”, Section 2.24, “REPLY”, and Section 2.25, “RETURN”.) If the RETURN instruction has no expression, RESULT is dropped (becomes uninitialized). Note that an EXIT or REPLY instruction also sets RESULT.
SELF
is set when a method is activated. Its value is the object that forms the execution context for the method (that is, the receiver object of the activating message). You can use SELF to:
  • Run a method in an object in which a method is already running. For example, a Find_Clues method is running in an object called Mystery_Novel. When Find_Clues finds a clue, it sends a Read_Last_Page message to Mystery_Novel:
    self~Read_Last_Page
    
  • Pass references about an object to the methods of other objects. For example, a Sing method is running in object Song. The code Singer2~Duet(self) would give the Duet method access to the same Song.
SIGL
is set to the line number of the last instruction that caused a transfer of control to a label (that is, any SIGNAL, CALL, internal function call, or trapped condition). See Section 11.3.4, “The Special Variable SIGL”.
SUPER
is set when a method is activated. Its value is the class object that is the usual starting point for a superclass method lookup for the SELF object. This is the first immediate superclass of the class that defined the method currently running. (See Section 1.7, “Classes and Instances”.) If the current method was defined by a class in the direct inheritance chain, SUPER will always refer to the immediate superclass that class. If the current method is defined by a mixin class, the SUPER variable will always be the superclass of the mixin class.
The special variable SUPER lets you call a method in the superclass of an object. For example, the following Savings class has INIT methods that the Savings class, Account class, and Object class define.

Example 17.1. Using the SUPER variable

::class Account

::method INIT
expose balance
use arg balance
self~init:super          /* Forwards to the Object INIT method  */

::method TYPE
return "an account"

::method name attribute

::class Savings subclass Account

::method INIT
expose interest_rate
use arg balance, interest_rate
self~init:super(balance) /* Forwards to the Account INIT method */

::method type
return "a savings account"

When the INIT method of the Savings class is called, the variable SUPER is set to the Account class object. The instruction:
self~init:super(balance) /* Forwards to the Account INIT method */
calls the INIT method of the Account class rather than recursively calling the INIT method of the Savings class. When the INIT method of the Account class is called, the variable SUPER is assigned to the Object class.

Example 17.2. Forwarding an event

self~init:super          /* Forwards to the Object INIT method  */

calls the INIT method that the Object class defines.
You can alter these variables like any other variable, but the language processor continues to set RC, RESULT, and SIGL automatically when appropriate. The EXPOSE, PROCEDURE, USE and DROP instructions also affect these variables.
Rexx also supplies functions that indirectly affect the execution of a program. An example is the name that the program was called by and the source of the program (which are available using the PARSE SOURCE instruction). In addition, PARSE VERSION makes available the language version and date of Rexx implementation that is running. The built-in functions ADDRESS, DIGITS, FUZZ, FORM, and TRACE return other settings that affect the execution of a program.