Contents Previous Next Subchapters

Executing The Function Corresponding To A String
Syntax feval(function namearg1arg2... , argn)
See Also argument functions , variable functions

Executes the function with the specified name and with the arguments arg1, arg2, ... , argn.

If you enter
     function square(x) begin
          return x^2
     feval("square", 2)
O-Matrix will respond

Argument Functions
Using this syntax, you can use strings in place of functions both as variables and as arguments to other functions. If you continue the example above by entering
     function g(fun) begin
          return feval(fun, 2)
O-Matrix will respond

Multiple Returns
The feval syntax can be used with multiple return values. If you enter
     function [x, y] = f(a, b) begin
          x = a
          y = b
     [u, v] = feval("f", 1, 2)
     print u, v
O-Matrix will respond
     1 2

The function name cannot correspond to a variable function and it cannot be local to a file. The argument function and variable function syntax do not have this restriction. In addition, using strings instead of functions as arguments and variables may not as fast to execute when there is a very large number of functions defined in a program.