One Liner Functions

A function that can be represented by a single formula can be defined as a single line map using the symbol ->. For example, function can be defined by

>>   f = x -> 2*x^2 - 3/x;
>>   f(3)
     17
Here x is the name of the formal argument, and will not be confused with the variable named x in the surrounding environment (if there is any) of the function. The right hand side of -> is an expression involving constants, the formal argument, and global variables. The local variables of the surrounding environment are invisible on the right hand side of ->.

If the function has more than one argument, they can be included in a pair of parentheses. For example

	f = (x, y) -> 2*x - y;

If there is no input argument, use a pair of empty parentheses.

>>	f = () -> rand(1)^ 2; //define a function with no input

>> f()    // call it
        0.1156542049
One-linear functions that have no output arguments are useless and therefore not allowed.



oz 2009-12-22