Product SiteDocumentation Site

7.4.4. ARG (Argument)


>>-ARG(--+----------------+--)---------------------------------><
         +-n--+---------+-+
              +-,option-+

Returns one or more arguments, or information about the arguments to a program, internal routine, or method.
If you do not specify n, the number of arguments passed to the program or internal routine is returned.
If you specify only n, the nth argument object is returned. If the argument object does not exist, the null string is returned. n must be a positive whole number.
If you specify option, the value returned depends on the value of option. The following are valid options. (Only the capitalized letter is needed; all characters following it are ignored.)
Array
returns a single-index array containing the arguments, starting with the nth argument. The array indexes correspond to the argument positions, so that the nth argument is at index 1, the following argument at index 2, and so on. If any arguments are omitted, their corresponding indexes are absent.
Exists
returns 1 if the nth argument exists; that is, if it was explicitly specified when the routine was called. Otherwise, it returns 0.
Normal
returns the nth argument, if it exists, or a null string.
Omitted
returns 1 if the nth argument was omitted; that is, if it was not explicitly specified when the routine was called. Otherwise, it returns 0.
Here are some examples:

Example 7.8. Builtin function ARG

/*  following "Call name;" (no arguments) */
ARG()         ->    0
ARG(1)        ->    ""
ARG(2)        ->    ""
ARG(1,"e")    ->    0
ARG(1,"O")    ->    1
ARG(1,"a")    ->    .array~of()

/*  following "Call name 'a', ,'b';" */
ARG()         ->    3
ARG(1)        ->    "a"
ARG(2)        ->    ""
ARG(3)        ->    "b"
ARG(n)        ->    ""    /* for n>=4 */
ARG(1,"e")    ->    1
ARG(2,"E")    ->    0
ARG(2,"O")    ->    1
ARG(3,"o")    ->    0
ARG(4,"o")    ->    1
ARG(1,"A")    ->    .array~of(a, ,b)
ARG(3,"a")    ->    .array~of(b)

Notes:
  1. The number of argument strings is the largest number n for which ARG(n,"e") returns 1 or 0 if there are no explicit argument strings. That is, it is the position of the last explicitly specified argument string.
  2. Programs called as commands can have only 0 or 1 argument strings. The program has 0 argument strings if it is called with the name only and has 1 argument string if anything else (including whitespace characters) is included in the command.
  3. Programs called by the RexxStart entry point can have several argument strings. (See the Open Object Rexx: Programming Guide for information about RexxStart.)
  4. You can access the argument objects of a program with the USE instruction. See Section 2.30, “USE” for more information.
  5. You can retrieve and directly parse the argument strings of a program or internal routine with the ARG or PARSE ARG instructions.