<function name="my:foo" as="number">
<param name="p" as="number"/>
<param name="q" as="number"/>
<sequence select="$p + $q"/>
</function>
Compact syntax introducing params
and select
attributes, with params
using the ParamList
construct from XQuery:
<function name="my:f" as="number" params="p as number, q as number" select="$p+$q"/>
Even more compact, suggested by @ebruchez syntax using part of the FunctionDecl
construct from XQuery:
<function signature="my:f(p as number, q as number) as number" select="$p+$q"/>
- Downsides:
- Marginally harder to parse.
- Less XMLish. (Which arguably, can be seen as an advantage.)
- Upside: compactness, obviously. This is particularly important as this construct would often be used to avoid code duplication by moving a common sub-expression into a function. If the syntax to declare a function is too cumbersome, some will judge the remedy to be worse than desease.
Comments on 'Evaluation context':
Comments on 'compact syntax':