The following built-in functions are functions that deal with arguments/variables.

ARG Returns an argument passed to a script/subroutine.
DATATYPE Checks a string's (or variable's) type.
SYMBOL Determines whether a particular string is also the name of an existing variable.
VALUE Returns the value of a variable whose name is constructed dynamically.


ARG

Returns a count of how many arguments were passed to a script/subroutine. Can also be used to fetch the value of any one of those arguments.

Synopsis
value = ARG(arg_number)

Args

arg_number is the argument number whose value is to be returned, where the first argument is 1. If arg_number is omitted, then a count of the number of passed args is returned.

Returns

Either a count of the number of args passed to the current script/subroutine, or the value of one of those args (or an empty string if no such arg exists).

Notes

This returns arguments for the current level. For example, if called from the main body of a REXX script, this returns the args passed to that REXX script. If called from some subroutine within the REXX script, then it returns the args passed to that subroutine.

Examples

Example use
Return value
ARG()
/* Returns how many args have been passed */
ARG(1)
/* Returns the value of the first passed arg */

See also

PARSE ARG


DATATYPE

Checks a string's (or variable's) type. For example, this may be useful to check whether a variable has a numeric value before attempting to use it in a mathematical expression.

Synopsis
result = DATATYPE(value, type)

Args

value is the string whose type is to check. For example, this may be the value of some variable. If type is omitted, then DATATYPE() will return 'NUM' if value is numeric, or 'CHAR' otherwise.

type is which type that value should be checked for. It is one of the following:

Option
Meaning
N (Number) Returns '1' if value is a numeric string (in base 10). This means that it contains only a leading '+' or '-' character, followed by the characters '0' to '9' inclusive, and perhaps one decimal point or one 'E' for an exponent.
A (Alphanumeric) Returns '1' if value contains only characters from 'a' to 'z', 'A' to 'Z', or '0' to '9', inclusive.
W (Whole) Returns '1' if value is a numeric string that is a whole number. This means that it has no fractional part (that is non-zero). For example, 25 is a valid whole number, but 25.5 is not. 25.0 would also be a valid whole number since its fractional part is 0. The NUMERIC settings are taken into consideration when checking if value is a whole number
B (Bits) Returns '1' if value is a valid binary string. This means that it contains only characters '0' or '1', inclusive. Spaces can be allowed inbetween nibbles or bytes (but not any leading or trailing spaces).
X (Hexadecimal) Returns '1' if value is a valid hexadecimal string. This means that it contains only characters from 'a' to 'z', 'A' to 'Z', or '0' to '9', inclusive. Spaces can be allowed inbetween bytes (but not any leading or trailing spaces).
S (Symbol) Returns '1' if value is a valid symbol (ie, tail) name. This is not necessarily a valid variable name. You should use SYMBOL() to test for a valid variable name.
L (Lower case) Returns '1' if value contains only characters from 'a' to 'z' (ie, lower case letters only).
U (Upper case) Returns '1' if value contains only characters from 'A' to 'Z' (ie, upper case letters only).
M (Mixed case) Returns '1' if value contains only characters from 'a' to 'z' or 'A' to 'Z', inclusive (ie, alphabetic characters only).

Returns

Either 'NUM' or 'CHAR' if type is omitted, or a 0 or 1 if type is specified.

Notes

For 'X' or 'B' type, if value is an empty string, then DATATYPE() will return a 1. For all other types, an empty string will return 0.

The result from 'A', 'L', 'M' and 'U' type may depend on the setting of language, if you are using an interpreter that supports national character sets.

Examples

Example use
Return value
DATATYPE('100.5')
'NUM'
DATATYPE(' - 1.35E-5 ')
'NUM'
DATATYPE('123.456')
'NUM'
DATATYPE('123.456.789')
'CHAR' /* Because of two decimal points */
DATATYPE('')
'CHAR'
DATATYPE('FooBar', 'A')
1
DATATYPE('Foo Bar', 'A')
0 /* Because of the space in 'Foo Bar' */
DATATYPE('0110 1101','B')
1

See also

SYMBOL, VALUE


SYMBOL

Determines whether a particular string is also the name of an existing variable (ie, one that has been explicitly assigned a value -- not one that is DROP'ed or never was assigned a value). Also can be used to check for a legal variable name.

Synopsis
result = SYMBOL(name)

Args

name is the string to check if it is a valid variable name with an assigned value.

Returns

Returns 'VAR' if name is the name of an existing variable that has been assigned a value. Returns 'BAD' if name is not a legal variable name, nor a numeric string. Returns 'LIT' if name is either a numeric string, or a legal variable name that has not yet been assigned any value.

Notes

If name is a compound variable name (ie, with tail names separated by dots), then tail name substitution may be performed upon the tails.

Make sure that you enclose name in quotes if you wish to check that particular name. Otherwise, SYMBOL() will assume that you are specifying a variable whose value should be checked to see if it is an existing variable's name.

Examples

Assume that 'MyVar' has been assigned the value '100'.

Example use
Return value
SYMBOL('MyVar')
'VAR'
SYMBOL(MyVar)
'LIT' /* MyVar's value is '100', which is not a legal variable name */

See also

DATATYPE


VALUE

Returns the value of a variable. Can also optionally set that variable to a new value. Furthermore, VALUE() allows setting/querying the value of an environment variable.

Synopsis
value = VALUE(name, new_value, environment)

Args

name is the variable's name.

new_value is the new value for the variable. If omitted, then the variable's value is not changed.

If environment is specified, then it is assumed that name is the name of some external variable (ie, a variable not maintained by REXX, and not contained in the REXX script itself). environment would be the name of the entity that maintains that variable. Possibilities for environment are 'SYSTEM', 'OS2ENVIRONMENT', or 'ENVIRONMENT' to set or query environment variables (ie, operating system variables). If environment is omitted, then the variable is assumed to be one of REXX's internal variables (ie, a variable in the REXX script).

Returns

The current value of the variable. If new_value is supplied, then the returned value is the previous value of the variable (ie, before its value is changed).

Notes

If you know the name of a REXX variable, then you can assign it a value just by using an equal sign. So too, you can use a variable's value just by specifying its name (unquoted) anywhere that you want to use its value. So, VALUE() is not needed for REXX variables whose name is known at the time that a script is being written.

The VALUE() built-in in used primary to set/fetch values of either environment variables, or REXX variables whose names aren't known ahead of time. For example, perhaps your script will ask the user to type the name of some variable. Your script will not know ahead of time what he will type. Let's assume that you store the variable name he types in another variable called 'TheName'. Here's how you would set his variable (whose name he provided) to the value 'something':

/* Get a variable name from the user */
SAY "Enter a variable name:"
PARSE PULL TheName
/* Set that variable's value to 'something' */
old = VALUE(TheName, 'something')

Assume that the user types 'MyVar' at the prompt. VALUE() does not set the variable 'TheName' to the value 'something'. Instead, it sets 'MyVar' to 'something'. It may be helpful to think of 'TheName' as being analogous to a "handle" in another language such as C. REXX doesn't have handles. So, the VALUE() function allows you to treat a variable as if it were a handle (ie, points to another variable) -- by assigning the name of the other variable to the "handle" and then using that "handle" with VALUE(). Above, 'TheName' is used like a handle to 'MyVar'.

On Windows, Reginald supports creating/querying/setting/deleting the values of registry keys and values (under HKEY_CURRENT_USER) via VALUE(). See Windows Registry for further details.

If an external variable hasn't yet been assigned a value or doesn't exist, then VALUE() returns an empty string.

If a REXX internal variable hasn't yet been assigned a value, then the value returned will be the variable's name upper-cased. For example, if you query the value of the REXX variable 'Blort', and that variable has not yet been assigned any value, the return string from VALUE() is 'BLORT'.

If name is a compound variable name (ie, with tail names separated by dots), then tail name substitution may be performed upon the tails.

See also

GETENV, SYMBOL