BBL - Basic syntax
B.3. The Output of Functions

Every function outputs one or more values. This is obvious in the case of (SIN x), but it is equally true in less obvious situations:
<7>> (PRINT (SIN x))
::
-0.6636339
-0.6636339

Why two numbers? PRINT, as you might imagine, is intended to display whatever value it's given, and it does so. But apart from what it does, it is also a function that outputs a value. In another world it might output a message "Printing accomplished!", but in this world, it outputs the value it printed. So that value appears twice. This may strike you as foolish, but it is a very useful behavior when constructing compound functions (to be discussed shortly).
<8>> (ASSIGN biggest-length = 0)
:: 0
<9>> (FOR-EACH gene IN (GENES-OF S6803)
            AS length = (LENGTH-OF gene)
            DO (ASSIGN biggest-length = (MAX biggest-length length)))
:: NIL
Never mind for the moment what this statement does... it ought to do something, and so it might be pretty discouraging to see NIL emerge as the result. The statement did do something -- it found the length of the biggest gene of Synechocystis PCC 6803 (Try entering biggest-length at the command line). But the number was not the output of the function FOR-EACH. The output was NIL.

You generally don't have to concern yourself with such issues. However, appreciating the distinction between the action of a function (also called the side-effect) and the output of the function may sometimes help you explain otherwise mysterious results.

Back to Table of Contents         Continue