Contents Previous Next Subchapters

Functions As Arguments
Syntax function argument name
See Also arguments , strings to functions

Description
Defines an argument as a user-defined function.

Tutorial
A function definition may contain user-defined functions in its argument list. If you enter
     clear
     function trigdeg(function trigfun, degrees) begin
          rad = PI * degrees / 180
          return trigfun(rad)
     end
     function secant(x) begin
          return 1. / cos(x)
     end
you can then find the secant of 45 degrees by entering
     print trigdeg(function secant, 45)
to which O-Matrix will respond
     1.41421
Only user-defined functions can be arguments. For example, to use the sin function as an argument, you must make it a user-defined function. If you enter
     function sine(x) begin
          return sin(x)
     end
you then can find the sine of 45 degrees by entering
     print trigdeg(function sine, 45)
to which O-Matrix will respond
     0.707107
If a function is an argument, it cannot be accessed using arg notation. If you continue the example above by entering
     function h() begin
          print arg(1)
     end
     h(function secant)
O-Matrix will respond with an error message.