Contents Previous Next Subchapters

Functions As Variables
Syntax function new function = existing function ( implicit arguments )
See Also arguments , local variable functions , strings to functions

Creates a new function with the same or fewer arguments as an existing function. The implicit arguments are an identifier list that is passed to the new function without being specified in the call.

If you enter
     function  residual(d, t, x) begin
          return d - x * t
     Time       = seq(3)
     Data       = 2 * Time 
     function f = residual(Data, Time)
     print f(1)
O-Matrix will respond
because f(1) is evaluated as residual(Data, Time, 1).

Functions defined in this way are referred to as variable functions . The implicit arguments in a function assignment statement can themselves be functions.

This feature is useful when using a general purpose utility that expects a function of a specific type. For example, you could use the variable function f defined above to solve the problem
     minimize |f(x)|  with respect to x
as follows
     level   = 0
     maxit   = 20
     x0      = 1.
     scale   = 1.
     result  = nlsq(function f, x0, scale, maxit, level)
     xout    = result.col(coldim(result))
     print xout
to which O-Matrix would respond