-
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
Proposal to support optional parameter values on static functions. #155
Comments
This is a good start, but the proposal is far from complete. Giving an example of old syntax and an example of new syntax and stating that they are equivalent does not constitute a specification. In addition, defining the semantics of the default value using this approach has problems. It would prevent the use of a default such as ".", because "." is undefined within a function body. If we want to allow that, then specifying the semantics of a variadic function declaration in terms of a lexical expansion to a set of non-variadic function declarations isn't going to work. There's a lot of prose in the spec that presumes a one-to-one correspondence between function declarations and functions in the static context, and therefore a lot of editorial work to handle the fact that this can no longer be assumed. |
I wanted to specifically only define the problem initially, not go into the specifics. That is, this is a high-level view of what is to be achieved. Think of this draft as being from the user's perspective. |
A pull request to implement this for XSLT and XQuery has been submitted. |
I believe this can now be closed as completed. |
This proposal allows users to define optional parameters for a function. When calling the function statically (e.g.
f(1,2,3)
), or creating a named function reference to it (e.g.f#3
), any optional parameters that are not specified take the default values.Motivation
Defining functions that can take one or more optional argument (such as in the Functions and Operators specification) adds a lot of boilerplate code. For example, `fn:tokenize could be written as:
In this proposal, the above can be written more simply and concisely as:
Both of these definitions of
fn:tokenize
are equivalent.Note
Once this proposal has been accepted, we should go through the XSLT and XQFO specifications and use defaults for all the relevant functions.
The text was updated successfully, but these errors were encountered: