3-12-1. Creating a recursive macro
It is possible to create special so-called recursive macros, which are filled up with modules only when you ask for a calculation.
3-12-1. Creating a recursive macro
Let us build a macro called Recursive macro from the following program :
This macro has only one input pin and no image on its front panel. It contains both calculation and visualization operators.
Now, let us do something that is permitted only in this very particular case : we select the Recursive macro box, slide it into its own interior and connect it :
This new box is empty, but will be filled up with a similar content as soon as we ask for its calculation.
The constraint that recursive macros should have only one input pin can easily be overcome, for this input pin can as well be linked to a clustered link (see clustered links).
3-12-2. Using recursive macros
Let us start with this graph :
Right-click on the Recursive macro box to launch its calculation. The macro opens and the result is shown below :
The +1 operation has been carried out and the name of the macro inside the first one has been changed. Now, if we calculate the Recursive macro,1 box, the macro fills with modules and we obtain :
and so on.
Only the memory limits the number of recursive levels that can be calculated this way. If a level is closed, the boxes inside are deleted. They will be recreated when a calculation is asked for.
Recursive macros are emptied when the program is saved. However, if a recursive macro is unlocked or put into an image, it is not considered as recursive any more : it will be recorded in the graph when the program is closed.
3-12-3. Examples of use of recursive macros
The principle of recursive macros is useful to create custom one- or two-dimensional graphical zooms. This is shown in the example about recursive macros provided with the software.