3.7 Program Feature Functions

These functions provide for explicit control sequencing, and the definition of blocks altering the scope of local variables.

GO(LABEL:id) noeval, nospread
 
GO alters the normal flow of control within a PROG function. The next statement of a PROG function to be evaluated is immediately preceded by LABEL. A GO may only appear in the following situations:
  1. At the top level of a PROG referencing a label which also appears at the top level of the same PROG.
  2. As the consequent of a COND item of a COND appearing on the top level of a PROG.
  3. As the consequent of a COND item which appears as the consequent of a COND item to any level.
  4. As the last statement of a PROGN which appears at the top level of a PROG or in a PROGN appearing in the consequent of a COND to any level subject to the restrictions of 2 and 3.
  5. As the last statement of a PROGN within a PROGN or as the consequent of a COND in a PROGN to any level subject to the restrictions of 2, 3 and 4.

If LABEL does not appear at the top level of the PROG in which the GO appears, an error occurs:

***** LABEL is not a known label

If the GO has been placed in a position not defined by rules 1-5, another error is detected:

***** Illegal use of GO to LABEL

PROG(VARS:id-list, [PROGRAM:{id, any}]):any noeval, nospread
 
VARS is a list of ids which are considered fluid when the PROG is interpreted and local when compiled (see “Variables and Bindings”, section 3.6 on page 35). The PROGs variables are allocated space when the PROG form is invoked and are deallocated when the PROG is exited. PROG variables are initialized to NIL. The PROGRAM is a set of expressions to be evaluated in order of their appearance in the PROG function. Identifiers appearing in the top level of the PROGRAM are labels which can be referenced by GO. The value returned by the PROG function is determined by a RETURN function or NIL if the PROG “falls through”.

PROGN([U:any]):any noeval, nospread
 
U is a set of expressions which are executed sequentially. The value returned is the value of the last expression.

PROG2(A:any, B:any)any eval, spread
 
Returns the value of B.
EXPR PROCEDURE PROG2(A, B);

  B;

RETURN(U:any) eval, spread
 
Within a PROG, RETURN terminates the evaluation of a PROG and returns U as the value of the PROG. The restrictions on the placement of RETURN are exactly those of GO. Improper placement of RETURN results in the error:

***** Illegal use of RETURN