Contents Previous Next Subchapters

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

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

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

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)
     end
     g("square")
O-Matrix will respond
     4

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
     end
     [u, v] = feval("f", 1, 2)
     print u, v
O-Matrix will respond
     1 2

Reference
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.