FutureBasic Logo

<<    Index    >> FutureBasic 5

def fn <prototype>   statement

def fn functionName [(var1 [,var2 ...])]

This statement declares a prototype for a local fn. The functionName and the argument list (var1, var2 etc.) must match those of some local fn whose definition appears later in the source code stream.
A local fn must either be defined (using a local fn...end fn block) or prototyped (using def fn <prototype>) before it can be referenced in any fn <userFunction> statement. By prototyping the function early in the code, you can call fn <userFunction> above the spot where the local fn...end fn block actually appears. This frees you from concerns about how to order your local fn blocks in the code.

In the following excerpt, fn myFn1 calls fn myFn2, and fn myFn2 calls fn myFn1. This kind of construction would be difficult to implement without prototyping the functions.
def fn myFn1(x as long)
def fn myFn2(x as long)

   input "Enter a number", k
   print fn myFn1(k)
until k = 0

local fn myFn1(x as long)
   if x mod 1 then z = 3 * x else z = fn myFn2(x) + 6
end fn = z

local fn myFn2(x as long)
   if x mod 1 then z = fn myFn1(x) - 1 else z = x / 2
end fn = z

See Also:
fn <userFunction>