By Andrew J. Wozniewicz
Milwaukee, August 16, 2008
To "invoke" a module is to "call" it like a procedure or function. In WANTScript, all modules are callable subroutines that can be invoked by referring to their name whenever a statement is allowed. For example:
The two nested modules, named
Test2, are invoked inside the module
TestProcs, just like procedures would be. In fact, given that you can use the keywords
procedure as an alias for
module in this context, the preceding example can be re-written in the following way, to make it more intuitive to a Pascal programmer:
The only things missing from the preceding example, that would make it a valid Pascal program, are the word "begin" in a few places, and the period at the end. The output of both versions of this program/module is – predictably – as follows:
Not-so-obvious to a Pascal programmer is the fact that one can also invoke the top-level module
TestProcs just like a procedure. This is akin to calling a Pascal unit directly by name, which is not allowed in Pascal (the code of a unit – its initialization section – is automatically called by the runtime). Here, the module that was previously treated as a top-level program, is now used both like a subroutine and importable library:
This program produces exactly the same output as before:
The difference with the previous example is that the module
TestProcs is called as a procedure from within
ExerciseTestProcs – it is no longer used as a top-level module, but as a callable subroutine.
In general, in WANTScript, any module can potentially be called as a subroutine. Calling a module as a subroutine runs its executable statements, if any.
A top-level module run from the command line is simply being called just like a subroutine by the WANT Runtime Engine.