I need to reference procedures that are defined further down in the program text. It's not possible to re-arrange the code in a way that this can be avoided (use case: a state machine, where each state is represented by a procedure, and certain state changes will require forward refs). (Astrobe) Oberon does not seem have a language facility for forward refs -- I scanned the Oberon docs and books for any hints or examples, to no avail, but then again, I might have missed them.
Of course, the problem can be solved using procedure variables.
Did I miss something, or are procedure variables the only solution?
Forward References
-
- Site Admin
- Posts: 534
- Joined: Fri Dec 31, 2010 12:30 pm
- Contact:
Re: Forward References
You are right. When programming in Oberon-07, in general the best solution (when you can't otherwise avoid calling a procedure that is not defined until later) is to use a procedure variable.
However, in some scenarios a nested procedure might be a preferable alternative e.g. one of Wirth's examples is as follows:
If, for example, P calls Q and Q calls P, the forward reference might possibly be eliminated by nesting, namely if one of the procedures is called only from within the other:
However, in some scenarios a nested procedure might be a preferable alternative e.g. one of Wirth's examples is as follows:
If, for example, P calls Q and Q calls P, the forward reference might possibly be eliminated by nesting, namely if one of the procedures is called only from within the other:
Code: Select all
PROCEDURE P;
PROCEDURE Q;
BEGIN … P …
END Q;
BEGIN … Q …
END P;