Function prototype: Difference between revisions

Content added Content deleted
(→‎{{header|SNOBOL4}}: Expanded on SNOBOL4 example.)
Line 887: Line 887:


With this structure the "function" is declared at the program, the implementation is somewhere down in the middle, and the mainline (<code>test</code> here) is at the end.
With this structure the "function" is declared at the program, the implementation is somewhere down in the middle, and the mainline (<code>test</code> here) is at the end.

The <code>define()</code> BIF is used for more than merely providing function-like access to a label with the same name. It is used to prototype all of these (with some default behaviour):

* the function name (<code>multiply</code> in the examples);
* the formal arguments to the function (<code>a, b</code> in the examples);
* the entry point label for the function's code (defaults to the function name);
* any local variables which should be protected in the function (defaults to none).

Thus a highly-contrived example function that illustrates all of these would look like this:

<lang snobol4> define('multiply(a,b)acc1,acc2','mult_impl') :(mult_end)
mult_impl acc1 = a
acc2 = b
multiply = acc1 * acc2 :(return)
mult_end

* Test
output = multiply(10.1,12.2)
output = multiply(10,12)
end</lang>


=={{header|zkl}}==
=={{header|zkl}}==