Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
In a function definition, name is the name associated with the function. As indicated in the examples above, name is optional. If it is present while compiling the function definition Glish creates a variable with that name whose value is the resulting function value. This name can then be used to call the function.
If the name is missing then presumably the function definition is being used in an expression. The resulting function value is then assigned to a variable or passed as an argument to another function. To illustrate the latter, here is a function that takes two parameters, a vector and another function. It prints out the result of applying the function to each element in the vector:
func apply(array, f) { for ( a in array ) print "f(", a, ") =", f(a) }You then call this function as follows:
square := func(x) x^2 apply( 1:10, square )to print out the squares of the first ten positive integers. You can also call it using:
apply( 1:10, func(x) x^2 )