Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


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 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 )


next up previous contents index
Next: Function Parameters Up: Functions Previous: Function Definitions   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15