4 Program Control
, ... argn
function has the syntax of an operand and is the function to be called. The args have the syntax of expressions, and are the arguments to the function. The function will often be a named value reference, but it can be any other kind of operand as well.
In the following example, the function being called is the value of the binding
average(x, y)In the following two examples, the function being called is the value of a
methodstatement. The examples differ only in that the second example puts parentheses around the
methodstatement, to make the code somewhat more readable.
method(x) x + 1 end (99) (method(x) x + 1 end) (99)In the following examples, the function being called is the result of another function call.
key-testtakes a collection as an argument, and returns a predicate function. The predicate function is then applied to the two keys. The following three program fragments will have the same effect.
key-test(collection)(key1, key2) (key-test(collection))(key1, key2) begin let fun = key-test(collection); fun(key1, key2); end
.functionapplies function to argument. This syntax is commonly used for slot reference, to access the function slot of argument.
Order of execution aside, the following pairs of function calls are equivalent:
america.capital capital(america) window.position position(window)Slot reference syntax can be cascaded and is left associative. Order of execution aside, the following pair of expressions are equivalent. Each returns the origin of the root-view of a window.
[i]is equivalent to the function call
element(sequence, i). The syntax array
]is equivalent to the function call
Order of execution aside, the following pairs of expressions are equivalent:
*all-windows* element(*all-windows*, 0) *tic-tac-toe*[1, 2] aref(*tic-tac-toe*, 1, 2)The names
arefare looked up in the environment of the element reference expression.
Generated with Harlequin WebMaker