4.2 Function Calls
An expression followed by a parenthesized sequence of expressions is parsed as an implicit use of the #%call form, which is normally bound to implement function calls.
expression | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
repetition | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
expression | ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||
|
If the arg sequence contains & list_expr or repet , ellipses, then the elements of the list or repetition are spliced into the call as separate by-position arguments.
If the arg sequence contains ~& map_expr, then all the keys in the immutable map produced by map_expr must be keywords, and they must not overlap with the directly supplied keywords or keywords in maps from other ~& map_expr arguments. The keyword-value pairs are passed into the function as additional keyword arguments.
Parallel to fun, a single keyword as an arg is equivalent to the form keyword: id This kind of double duty of a single keyword is sometimes referred to as “punning.” where id is composed from keyword by taking its string form and lexical context.
The case with an immediate _ group among other args is a special case for a function shorthand, and it takes precedence over parsing the _ as an arg. See _ for more information.
See also use_static.
The #%call form is implicitly used when (…) is used after another expression in an expression position. See also Implicit Forms.
> List.length([1, 2, 3])
3
> List.length #%call ([1, 2, 3])
3
Alternatively, the right-hand side can be an immediate callee, in which case the static information for arg_expr is supplied to it.
A _ function shorthand can be especially useful with |>.
> [1, 2, 3] |> List.length
3
> [3, 1, 2]
["0", "1", "2", "3", "100"]
> #false ?> List.length
#false