Numeric Conversion of Empty Strings in REXX
Under classic REXX semantics, an empty string used in an arithmetic context typically triggers a SYNTAX condition (specifically a numeric value required error) rather than being coerced to zero. Because REXX is weakly typed, it attempts to convert strings to numbers only when a numeric operator is encountered; if the string is empty or contains non-numeric characters, the conversion fails.
Implementation Behavior
While the general behavior is to raise a condition, specific implementations handle the failure and coercion differently:
- IBM z/OS REXX: Strictly follows the requirement for a valid numeric string. An empty string in an arithmetic expression will trigger a SYNTAX condition. It does not coerce empty strings to zero by default.
- ooRexx: Generally triggers a SYNTAX condition when an empty string is encountered in a numeric context, adhering to the standard's expectation that a value must be present for arithmetic.
- Regina REXX: Similarly treats empty strings as invalid numeric operands, raising a SYNTAX condition.
Detecting Divergent Conversion
To detect whether a conversion failed or to handle the lack of a numeric value without crashing the script, the caller should use the SIGNAL ON SYNTAX directive. This allows the program to trap the error and implement a fallback (such as assigning a default value of 0).
SIGNAL ON SYNTAX
/* Attempt arithmetic with potentially empty variable */
result = empty_var + 10
return
/* Error handler */
syntax:
say "Numeric value required: empty_var was not a number"
result = 10 /* Fallback: treat empty_var as 0 */
return
Verification Steps
To verify behavior across your specific environment versions, execute the following scoped test:
- Initialize a variable to an empty string:
var = "".
- Attempt a simple addition:
res = var + 0.
- Observe if the interpreter terminates with a "Numeric value required" error or silently assigns
res = 0.
Diagnostic Detail Required: Are you utilizing any specific NUMERIC DIGITS settings or custom SIGNAL traps that might be suppressing standard condition reporting in your current build?