next up previous contents index
Next: Function Parameters Up: Functions Previous: Function Definitions

Function Names

    In a function definition, name is the name associated with the function. As indicated in the examples above, name is optional. If it's present then when 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, and the resulting function value 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)
We could 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. We also could have called it using:
    square := func(x) x^2
    apply( 1:10, func(x) x^2 )

Thu Nov 13 16:44:05 EST 1997