[Next] [Up] [Previous]

The DEFINE Statement

The DEFINE statement
(DEF)

The DEFINE statement defines a function inside the program in which it is called, as does PFUN. However, the function itself, as well as its header, appears in the statement.

A typical DEFINE statement might look like this:

       DEFINE (REAL) SINH((REAL)X)=.5*(EXP(X)-EXP(-X))

also, the statement

       DEFINE (REAL)=(REAL)X &.OVER. (REAL)Y=X/Y

defines &.OVER. as a substitute for the REAL division operator. Note the presence of two equals signs, neither of which is a relational operator: the first one is part of the operator header, and the second assigns the definition of the operator to the operator. SUBROUTINES cannot be defined in this fashion. (However, an ALIAS statement may link a SUBROUTINE name to code including a DEFINEd function or operator, or to a function or operator used in the defining expression within a DEFINE statement.)

Note that if (REAL) were replaced by (MUTABLE) in the definition of SINH, a SINH function able to work on all types would be obtained. If (REAL) is instead omitted, DEFINE would generate one SINH function for each type X could have for which EXP(X) is valid. The idea of collections of functions, all having the same name, is explored more fully in the description of the ALIAS statement in a subsequent section.

If a function or operator in a DEFINE statement is recursive, that function must be used under its own name; the _SELF function and the &SELF operator are available also, but they refer to the subprogram in which the DEFINE statement appears. Like PSUB and PFUN, DEFINE statements appear among the type declaration statements of a program.


[Next] [Up] [Previous]