FUNCTION (define a function)

Top  Previous  Next

 

label

FUNCTION [(parameter list)]

 

local data

 

CODE

 

statements

 

RETURN(value)

FUNCTION is a statement which once defined a PROCEDURE prototyped to return a value (referred to as a function in some other programming languages). The FUNCTION keyword has been replaced by the PROCEDURE statement and is now a synonym for PROCEDURE in all cases.

Example:

PROGRAM

MAP

FullName FUNCTION(STRING Last,STRING First,<STRING Init>),STRING

                                 !Function prototype with parameters

DayString FUNCTION,STRING         !Function prototype without parameters

END

TodayString STRING(3)

CODE

TodayString = DayString()        !Function call without parameters

                                 ! the () is required for a function

 

FullName FUNCTION(STRING Last, STRING First,STRING Init)    !Full name function

CODE                             !Begin executable code section

IF OMITTED(3) OR Init =          !If no middle initial

 RETURN(CLIP(First) &   & Last)  ! return full name

ELSE                  !Otherwise

 RETURN(CLIP(First) &   & Init & .  & Last)                ! return full name

END  

 

DayString   FUNCTION              !Day string function

ReturnString STRING(9),AUTO       !Uninitialized local stack variable

CODE                             !Begin executable code section

RETURN(CHOOSE(TODAY()%7)+1,Sun,Mon,Tue,Wed,Thu,Fri,Sat))

 

See Also:

PROCEDURE