FutureBasic Logo

<<    Index    >> FutureBasic

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>