Functions encapsulate expressions that are useful in many different situations. A function executes when it is applied to an actual parameter. The general syntax of a function application is a function name followed by an expression. Some examples are all ("Class") and class current. Functions part of the Q language, and there is no way to define new functions.
All functions take a single parameter. Functions that appear to take more than one parameter really take a single tuple containing the parameters. Because all functions take a single parameter, it is not necessary to enclose the parameter in parentheses. Instead, the smallest complete expression following the name is taken to be the parameter. This rule of taking the "smallest complete" expression means that parentheses are sometimes necessary to indicate a larger expression for the parameter.
Two other aspects of functions are worth mentioning. First, function application is at the highest precedence level. Hence, function applications are usually evaluated earlier than operators, such as + and in composite expressions. Second, function application associates to the right.
To illustrate these points, consider two functions named inc and dec (these functions are not part of the Q language - they are used merely as examples). The function inc takes an integer and returns one plus that integer. The function neg takes an integer and returns the negation of that integer. Use the symbol ≡ in the following examples to show an equivalent but fully parenthesized counterpart to some expression.
inc 5 ≡ inc (5) ⇒ 6 neg 5 + 3 ≡ (neg (5)) + 3 ⇒ -2 neg (5 + 3) ⇒ -8 neg 5 + inc 3 ≡ (neg (5)) + (inc (3)) ⇒ -1 neg (5 + inc 3) ⇒ -9 neg inc 3 ≡ neg (inc (3)) ⇒ -4 neg inc 3 + 1 ≡ (neg (inc 3)) + 1 ⇒ -3 neg neg neg neg 3 ≡ neg (neg (neg (neg (3)))) ⇒ 3