Overview Module Function Class Tea 3.2.5 Reference Documentation
© 2009 PDM&FC

Function define

define varName
define varName value
define functionName formalArgs body

Creates a variable in the current context and initializes it with the given value or a newly created function.

Parameters:
varName - Symbol identifying the variable to be created in the current context.
value - The object for which the variable will hold a reference. This argument is optional. If not specified the variable will be assigned the null value.
functionName - Symbol identifying the function to be created in the current context. In other words, the name of the variable to be created in the current context and that will contain a new function object.
formalArgs - List of symbols representing the function formal arguments, or a symbol representing the list of formal arguments.
body - Code block object that will be used as the new function body.
Returns:
The contents of the newly created variable.

Example of defining a numeric variable:
    define pi 3.141516

Example of defining a function that calculates and returns the square value of its argument:
    define square ( x ) { * $x $x }

Example of defining a function which accepts a variable number of arguments:
    define lineEcho argList {
        foreach arg $argList {
            echo $arg
        }
    }

Defining the same variable more than once in the same context is legal. Subsequent definitions only change its value, just like if it was done through the function set!.

Overview Module Function Class Tea 3.2.5 Reference Documentation
© 2009 PDM&FC
Report a bug or request new features
© 2009