Chapter Contents |
Previous |
Next |
The CMS REXX SAS/C Interface |
Extending REXX with Function Packages |
Function packages are based on the programming concept
of grouping sets of instructions (routines), designed to perform some specific
task, outside of the mainline program. The REXX language allows calls to
routines internal to the program and external to the program. Internal calls
cause a branch to a routine identified by a statement label within the program.
External calls are made to routines that reside in files outside both the
user's program and the interpreter. Grouping similar external routines together
into a function package is the focus of this chapter. For example, function
packages typically are sets of related functions, such as
sin
,
cos
, and other trigonometric functions. Functions in a function package
can share common code and data, or each function can be independent of the
others.
The REXX interpreter recognizes three function
package names. RXSYSFN is supplied with REXX and contains functions that
interface with CP and CMS. The other two function packages are called RXUSERFN
and RXLOCFN and can be written by any REXX user. Function packages written
using the C language can use either of the names RXLOCFN or RXUSERFN. To find
and execute an external function, REXX goes through a specific search order.
For example, if a REXX statement such as the following refers to a name that
is not a label or the name of a built-in function, REXX searches for an external
function with the name
csqrt
:
root = csqrt(100)
REXX searches for an external function by prefixing the function name with RX (RXCSQRT, in our example) and invoking it as a CMS command. If such a program is found, REXX invokes it with the argument list. However, if no such command can be found, REXX then searches for the function in either RXUSERFN or RXLOCFN.
Within a REXX
program, routines in a function package can be
used either as functions or as subroutines. Because the C language does not
have subroutines or procedures, this means partitioning functions into two
types that REXX recognizes as functions or as subroutines. The distinction
is that functions must return a result; subroutines need not return a result.
A subroutine is called by the REXX CALL instruction. A function is called
with a function call. For example, a function named
csqrt
would be called as
x = csqrt(4)
. To use
csqrt
as a subroutine, the call would be
call csqrt(4)
.
The use of Adlen pairs is related to the way REXX handles
variable values. REXX keeps all its variable values, even numeric values,
as character strings. Each variable value is kept internally as a pointer
to a character string coupled with an
int
containing the length of the string. For example, given the following
REXX statement,
x
is a
string of length 3 with the value 100:
x = 100
REXX external functions must accept their parameter lists in this format and return values in this format to REXX. This is why function parameter lists are passed to the function in the form of an array of such Adlen pairs.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.