Thus far, we have only used Full Metal Jacket as a calculator. To go any further, we need to know how to define functions.

The calculation of

        sqrt(8.0 * 8.0 + 15.0 * 15.0)
shown in the previous tutorial can be wrapped up into the function hypotenuse:



The large rectangle enclosing the code is called an enclosure. This is equivalent to the lambda special form in Lisp dialects, and there are analogous constructs in other functional languages and Smalltalk. Its name describes its appearance, and was chosen because it sounds similar to closure. On the enclosure's top and bottom are gates. Those on the top are ingates, and those on the bottom are outgates. The gates with pink inputs are used to add gates while the function is being defined.

An example of code which calls hypotenuse, and its output, are:

hypotenuse call.png hypotenuse output

Previous Up Next

© Copyright Donald Fisk 2015