The AppleScript subroutines with
positional parameters are simple to design and use, as long as you
meet certain guidelines. The keywords
to are required in the subroutine definition,
followed by the name of the subroutine, and any parameters separated
by commas and contained in parentheses. You have to use empty
parentheses following the subroutine name if the subroutine will not
take any parameters. The subroutine’s name must
comply with AppleScript’s rules for identifiers. In
AppleScript, the names that you create for variables and subroutines
have to begin with a letter or underscore ( _ ) character, but
subsequent characters can include letters, numbers, and underscores.
Unless you begin and end the subroutine name with a vertical bar (|),
you cannot include AppleScript’s reserved words and
operators such as
+, or special characters
such as $, @, or #.
is required to signal the end of the subroutine definition. You can
end with the subroutine name for the sake
On Squared(n1)...end Squared
This is not required, however; the compiler, Script Editor, does it for you. You can declare and give values to variables in AppleScript subroutines, and use the various flow-control statements such as:
However, you cannot define another subroutine inside of a subroutine definition.
To call a subroutine, use the subroutine name followed by its parameters ...