Language Guide
CHAPTER 8
Handlers
234 Subroutine Definitions and Calls
The following subroutine uses the special label given to define a parameter
with the label rounding. By using verb forms ending with “ing” as labels, you
can often make subroutine calls easier to read.
to findNumbers of numberList above minLimit
given rounding:roundBoolean
set resultList to {}
repeat with i from 1 to (count items of numberList)
set x to item i of numberList
if roundBoolean = true then
copy (x + 0.5) div 1 to x
end if
if x > minLimit then
copy resultList & x to resultList
end if
end repeat
return resultList
end findNumbers
--to call findNumbers:
findNumbers of myList above 3 given rounding:true
Another way to call the findNumbers subroutine is to use a With or Without
clause to specify the value of the rounding parameter. You can use With or
Without clauses to specify parameters whose values are true or false.
--this call is equivalent to the previous example
findNumbers of myList above 3 with rounding
The subroutine parameter labels that can be used without the special label
given allow you considerable flexibility in defining handlers that sound
English-like. For example, here’s a routine that takes any parameter that
can be displayed as a string and displays it in a dialog box:
on rock around the clock
display dialog (clock as string)
end rock