Language Guide
CHAPTER 8
Handlers
228 Subroutine Definitions and Calls
the example calls the factorial subroutine. (You must have a compiled
script called Numeric Operations in the specified location for this script to
work correctly.)
set NumberLib to (load script file "MacHD:Scripts:Numeric Operations")
tell NumberLib
factorial(10)
end tell
Note
The Load Script scripting addition command loads the
compiled script as a script object. For a definition of Load
Script, see the AppleScript Scripting Additions Guide.
Script objects are user-defined objects that are treated as
values by AppleScript; for more information about them,
see Chapter 9, “Script Objects.”
◆
Subroutine Definitions and Calls 8
A subroutine definition contains
■ a template for calls to the subroutine
■ optional variable declarations
■ statements; among these can be a Return statement that when executed
returns a value and exits the subroutine
You cannot nest subroutine definitions; that is, you cannot define a subroutine
within a subroutine definition.
The way you call a subroutine is determined by the way the subroutine
was defined:
■ You must provide all the parameters specified in the definition.
■ You must provide either labeled parameters or positional parameters, as
specified in the definition.
The sections that follow describe how to define and call subroutines.