Forward Procedures (Advanced)

Top  Previous  Next

In XPL0, all names must be declared before they can be used. Procedures, in particular, must be declared before they are called. Occasionally, a situation arises in recursive programs where a procedure must be called before it is declared. The forward-procedure declaration solves this problem. It has the form:


        fprocedure NAME(COMMENT), ... NAME(COMMENT);


For example:


        fprocedure MakeNumber, TestGuess, Break, Repair;


This declaration tells the compiler that the four names listed are procedures that occur within the present procedure and at the current level. Now that these procedures are declared, they can recursively call each other without regard to the order that they are written.


"Fprocedure" declarations must occur immediately before "procedure" declarations; there cannot be any intervening variable declarations.