Functions
A function is a type of handler that is a source of value. SenseTalk provides many functions for a wide variety of purposes. Some functions may produce a different value each time they are used, such as the time
which provides the current time of day. Other functions may produce a different value depending on what parameters are passed to them—using the same function with different parameter values will produce different results. For information on passing parameters, see Parameters and Results.
The functions that are built-in as part of the SenseTalk language are described throughout this manual, especially in the Commands and Functions section. The host application environment in which SenseTalk is running may provide other predefined functions. In addition, you can write your own functions that can be used by your scripts. See Handlers for more information.
Calling Functions
To use a function value, a script "calls" that function, either on its own or as part of an expression. SenseTalk provides several different ways to call a function—you can use whichever one seems most natural in a given situation. The simplest type of function call is one without parameters that is not being sent to a particular object. Such a function call can be made in two ways: either by naming the function followed by an empty pair of parentheses (indicating no parameters); or by using the word "the" followed by the function name:
put date() -- displays the date
put the date -- displays the date
To call a function with a single parameter, either include that parameter in the parentheses after the function name, or follow the function name with "of" and the parameter:
put length("abcd") --> 4
put the length of "abcd" --> 4
In the second case above, because "of" is used, SenseTalk is able to recognize it as a function call even without the word "the":
put length of "abcd" --> 4
Because many functions (such as the "length" function) calculate some attribute of a value, SenseTalk also allows the property access notation to be used to call a function:
put "abcd"'s length --> 4
put "abcd".length --> 4