[Next] [Up] [Previous]

The PSUB Statement

The PSUB statement

The PSUB statement combines the functions of the SUBROUTINE and XSUB statements, as it begins the text of a subprogram, but it also appears within its caller's type declaration area. It is followed by the text of the subroutine which it declares, and this text terminates with an END statement. Following the END statement, the text encountered is that of the calling program.

Variables in the main program (or surrounding program, as PSUB statements are allowed within external and internal subprograms as well) are not accessible to the procedure so constructed, even if they are declared prior to its position, except where explicitly declared to be accessible (using the AVAILABLE or GLOBAL statements with the EXTERNAL statement, or COMMON blocks), unlike the practise in PASCAL.

Procedures (PSUB, PFUN) defined in the main program are accessible to all other procedures in the same program, whether or not the caller follows the subprogram called.

Since a PSUB statement describes how a subroutine is to be called to the caller, like the XSUB statement, and it also describes what the arguments are from the viewpoint of the program, the options for the XSUB and SUBROUTINE statements are all available; otherwise, the syntax of the XSUB statement is basically the same as that of the SUBROUTINE statement.

In addition, instead of using conventional separators for the arguments, arguments can instead be separated with minus signs (-); in this case, the first argument of the call is always assigned to the first argument in the header, and so on, except where two consecutive separators, or a leading separator, explicitly indicates the omission of an argument. %[(type)argument-] is also allowed.

The separator preceding an argument is determined by the function _PSEP(arg) which returns 0 for a comma, 1 for a semicolon, 2 for |, 3 for \, 4 for ?3; , and so on, -1 for a colon, -2 for ?1: , and so on. _FSEP(arg) can also be used, giving the code of the separator following an argument.

In EASY mode, this is even possible with external procedures.

[Next] [Up] [Previous]