-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support named arguments on static function calls #159
Comments
The use of keywords to identify function parameters in static function calls creates a problem in XSLT where a function defined in one package is overridden by a function in another package. The XSLT 3.0 rules do not require the overriding function to use the same parameter names. This differs from named templates, where there is such a requirement, included in the spec on the basis that the caller needs to know the parameter names. For functions, by contrast, it was assumed that parameter names were of local significance only. Several solutions come to mind, none of them especially attractive:
We also need to consider whether an overriding function should allow additional optional parameters to be declared that are not present on the overridden function, as we do for named templates. It's a bit trickier to achieve for functions because you can have multiple functions with the same name and different arity, and you might find yourself overriding a different function. In principle, one can imagine a single function declaration in a using package overriding several function declarations (with different arity) in the used package, or vice versa. We probably need a rule along the lines that the overridden package must contain exactly one function declaration whose arity range overlaps the arity range of the overriding function. |
The pull request for issue #155 supports this feature. |
In response to the comments on the PR, I propose to make the following changes.
|
Just in case this hasn’t been dealt with yet: Do we also want to support named parameters for type constructor functions? The current parameter name is |
We accepted this feature a while ago and the issue should have been closed. |
This proposal adds the ability to specify the names (referred to here as "keywords") of the parameters of a function at the point at which the function is called. This uses the form
name: value
where name is a QName and value is a single expression, for examplefn:tokenize("abcbdCef", pattern: "c", flags: "i")
.Motivation
If a function takes several arguments of the same type (xs:boolean, xs:integer, xs:string, etc.) it can be easy to mix up the parameters. As such, it can be useful to specify these by name when calling the function, e.g.
f(a: true(), b: false(), c: true())
to both aid readability and to prevent bugs when the values are specified in the wrong order to how they are declared (such as swapping the$pattern
and$flags
parameters infn:tokenize
).If a function takes several optional parameters and the caller only wants to override one of the later parameters (such as the
$collation
infn:differences
), specifying the name of the parameter avoids specifying a value for the other arguments. This makes it clearer what is happening (as the user does not need to think about the supplied default arguments), and reduces errors (such as specifying a wrong default value for the arguments the caller is not interested in).Notes
Because function parameter names are EQNames, the keyword should also be an EQName. If the keyword is an NCName, then it should follow the same rules as parameter NCNames such that the namespace URI is empty.
Like with maps, if the value starts with an element name (EQName) then there must be a space after the
:
. This should use the same note as the one in the map constructor section.An alternative
name := value
syntax has also been suggested. An informal consensus is in favour of usingname: value
.The text was updated successfully, but these errors were encountered: