Contents Previous Next Subchapters

Defining Functions With Variable Numbers Of Arguments
Syntax arg(value)
See Also arguments , nargin , nargout

References the specified function argument, where value is an non-negative integer scalar.

Number Of Arguments
If a function call does not have multiple return values , the expression arg(0) is equal to the number of arguments in a function reference. If you enter
     function f(a, b, c, d, e) begin
          print arg(0)
     f(2, 4, 6)
O-Matrix will respond

Referencing Arguments By Index
The expression arg(1) is equal to the first argument of the function, arg(2) is equal to the second argument, and so on.

If you enter
     function maximum() begin
          imax = 1
          for i = 2 to arg(0) begin
               if arg(i) > arg(imax) then imax = i
          return arg(imax)
     maximum(1., 5, 2., 6)
O-Matrix will respond

If an argument is a simple variable name, you can assign a new value to the argument using this notation (see arguments, Reference for a discussion of a simple variable). For example, if you enter
     function f() begin
          arg(2) = 3
     x = 5
     y = 6
     f(x, y)
     print x, y
O-Matrix will respond
     5 3