Metaprogramming: Difference between revisions

m
→‎{{header|SNOBOL4}}: Just taking ownership of the SNOBOL4 example.
m (→‎{{header|SNOBOL4}}: Just taking ownership of the SNOBOL4 example.)
Line 212:
The code now defines the <code>XADD</code> function and immediately, without doing initialization, jumps to the <code>XADD.END</code> label, bypassing both initialization and the function body. The trick here is that it defines the entry point of the function to be the <code>XADD.INIT</code> label. Now the first time <code>XADD</code> is called, control is transferred to <code>XADD.INIT</code>, the expensive initialization is performed, then the <code>XADD</code> function is *redefined* to point to the <code>XADD</code> label as the entry point. From this point onward all calls to <code>XADD</code> only perform the calculation, not the expensive initialization while the expensive initialization isn't paid at all unless the function is used at least once.
 
There are, of course, many other uses for function redefinition in this style which are usefulsuitable for metaprogramming efforts. Indeed such features are used prominently in the debugging subsystems of SNOBOL4 implementations.
 
=={{header|Tcl}}==