|
A couple more things came to mind:
You can use dynamic dispatch by building up the name of the sub-generator to call. At its simplest this is just including the name of a type in the generator names, e.g. _UI_Button, _UI_Menu etc., and then calling with subreport '_UI_' type run.
Getting more advanced, you can achieve dynamic dispatch based on multiple factors. For instance, you can use variables to pick which language or platform you are generating from, e.g. _UI_Java_Swing_Button, and call subreport '_UI_' $lang '_' $platform '_' type run. If most cases have a default, e.g. the same code for most platforms, you can first call _UI_Button and have that check the $platform variable and either do the default or re-dispatch as necessary.
You can make generators parameterizable by using variables. Setting the variables before calling is then the equivalent of passing arguments. You can get the equivalent of a function return value by having a particular variable that is set by the sub-generator. An alternative would be to wrap the call in a variable..write..close block, which will catch the output. Obviously, these "functions" are non-reentrant and non-recursive, but then MERL isn't really intended for implementing your own functional language  .
For readers less familiar with MERL: Before you move on to this more advanced approaches, though, make sure you have a good feel for http://www.metacase.com/support/45/manuals/mwb/Mw-5_3_1.html - MERL's normal approach . The strong focus on output streams, navigation and the stack make using MERL rather different from using standard 3GLs; they are also what make MERL better at its task than standard 3GLs would be.
|