-
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
Specify optional parameters to create bounded variadic functions #64
Comments
The following table lists the default values for the various parameters of the built-in functions. Where the "Changed?" column has a value of "yes", the parameter and function need signature and logic changes to support the default value; these changes are described in separate issues (#69 and #70). Using the default values means that the combined functions depend on all the context items that the currently separate versions do. That is, if the 2-argument version depends on the default collation, but the 3-argument version does not, then with the default values applied both versions depend on the default collation.
[1] The function is map-variadic, so those rules will supply the default [2] The default value in these cases cannot be evaluated statically, but require passing the context item at the point at which the function call is evaluated. [3] The default is specified here as the [4] The $description, $error-object, and $label arguments have implementation-defined default values. As such, the 0- and 1-argument versions of [5] The function gains additional 3- and 4-argument versions due to it having default values for the last 3 parameters. [6] By using the 5-argument version with default arguments, the $flags argument will be optional in the 4-argument case, as it is in the 5-argument version. As $flags is optional in the 5-argument version, it does not need changing to support default values. [7] The 1-argument version of the function will have a return type of |
Given the above analysis, and having experimented with optional parameters, there are two possibilities for defining the values for the optional arguments:
Evaluating Default Values
|
I wonder if it makes sense to restrict this to only defining and allowing constant value expressions, and then having separate issues for how to handle the |
Here are some possible designs to handle Design 1A possible way for supporting
Note: The way this is defined would mean that you can't pass a 0-arity function reference as a default parameter. Design 2Another possibility is to use a variant of design 1, but define a
Here, The semantics of
|
Is there any reason not to allow the default value to be any expression? The semantics are that the expression is evaluated in the dynamic context of the function call. This allows the default value for $collation functions such as Note that XSLT allows a named template to be defined with optional parameters (for example it allows The static context, of course, doesn't include the local variables of the caller. But (in the XSLT case) it does include global variables. |
I'm happy with that. So to confirm, If that is the case, we can just have:
Otherwise, we would need the DefaultExpr defined above:
|
Closing this as this is effectively what we ending up implementing. |
The current Editor's Draft for XPath and XQuery define a
%variadic("bounded")
function type, but does not define a syntax for specifying these.Grammar
Semantics
[Definition: a parameter is an optional parameter if it has a default value specified using the
:= ExprSingle
syntax.] Optional parameters affect the value of R (the number of parameters that do not have a default value) in the 4.4.1 Static Functions section.Notes
There are open questions on what to allow in the default value expression. Specifically, how to support things like the context item for functions such as
fn:data#0
that use the context item if not specified (e.g. when used at the end of a path expression).An investigation should be done on the standard functions and vendor built-in functions to see what values they take as defaults.
The text was updated successfully, but these errors were encountered: