Simple inline functions

An abbreviated syntax is available for defining simple inline functions. For example, the expression fn{.+1} represents a function that takes a single argument and returns the value of that argument plus one. A simple inline function takes a single argument with required type item(), and returns any sequence (type item()*). The function body is evaluated with a singleton focus based on the supplied argument value.

Simple inline functions are particularly convenient when providing functions as arguments to higher-order functions, many of which accept a single item as their one argument. For example, to sort employees in order of salary, you can write sort(//employee, fn{@salary}).

Simple inline functions can access externally-defined local variables in the usual way (that is, they have a closure).

The expression fn{EXPR} is a syntactic shorthand for function($x as item()) as item()* {$x!(EXPR)}.