t3x.org / t3x / t3x-manual / 282.html
 
T3X - A Minimum Procedural Language
Version 8.1.5, Online Edition
Copyright(C) 1996-2004
Nils M Holm
 
Previous:
2.8.1 Recursive Procedures
TOC | Index | Back Next:
2.8.3 Variadic Procedures

2.8.2 Mutually Recursive Procedures

Recursive procedures which depend on each other are called `mutually recursive'. Such a configuration introduces the following problem: Given the procedures

A() DO !...
        B();
END

B() DO !...
        A();
END

which depend on each other, it does not matter which one is declared first - one will always be inaccessible from within the other. In the above example, B is undefined in A because it is declared after A. When swapping the definitions, A will become undefined in B.

The problem is solved by introducing procedure declarations which may occur before the matching definition. A declaration makes a procedure symbol known to the compiler, but does not associate any meaning with it. In the case of procedures, the definition may be `subsequently delivered'. To declare a procedure, the DECL statement is used:

DECL name(type);

Any number of comma-separated declarations may be included in a single DECL statement. Name is the name of the procedure to declare and type is a constant expression specifying the number of formal arguments of that procedure. This value is required to type check forward calls to the procedure. The number of formal arguments in a subsequent definition must exactly match the type specified in the declaration. Otherwise, a redefinition error will be signalled.

DECL reserves the given names for later procedure definitions. Therefore, each of these names may only be re-used in one single procedure definition. Declaring a procedure without defining it later is an error, since this may leave forward references to the declared procedure unresolved.

To correct the above program fragment containing the mutually recursive procedures A and B, the declaration

DECL B(0);

has to be inserted before the definition of A. Like procedure definitions, DECL statements are only allowed at the top level and in class contexts, but not inside of local scopes.

Previous:
2.8.1 Recursive Procedures
TOC | Index | Back Next:
2.8.3 Variadic Procedures