Jump to content

Function definition: Difference between revisions

m
m (→‎{{header|Wren}}: Changed to Wren S/H)
imported>RonReu
Line 419:
end</syntaxhighlight>
 
A function in AppleScript is called a "handler". It can take one of three different forms, depending on what the scripter finds most convenient. Calls to it must match the form used in the handler definition. The above is an example of a handler with "positional" parameters. Either <code>to</code> or <code>on</code> may be used as the first word in the headerhandler linedefinition. When the script's is compiled, the handler label is automatically appended to the <code>end</code> line too if it wasn't written in.
 
Handler names followed by zero or more parameters within parentheses are called "positional" -- the number and order of the parameters in the caller must match those in the handler definition.
 
<syntaxhighlight lang="applescript">on multiply(a, b)
Line 427 ⟶ 429:
multiply(2, 3)</syntaxhighlight>
 
AppleScript also offers handlers with "labeledprepositional" [sic]labeled parameters. These aren't used muchoften now asbecause the limited choiceset of labelAppleScript-defined enumsprepositions makes it difficult to choose ones that make sense in English, although it's just about possible. here:
 
These prepositions can be used: <code>about, above, against, apart from, around, aside from, at, below, beneath, beside, between, by, for, from, instead of, into, on, onto, out of, over, since, thru, through, and under</code>. Also, <code>of</code> is also available, but if used it must be the first parameter.
 
Example:
 
<syntaxhighlight lang="applescript">on multiplication of a by b
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.