This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 9787 - [XQ31ReqUC] Default values for function arguments
Summary: [XQ31ReqUC] Default values for function arguments
Status: ASSIGNED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Requirements for Future Versions (show other bugs)
Version: Working drafts
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Jim Melton
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on: 9062
Blocks:
  Show dependency treegraph
 
Reported: 2010-05-21 11:05 UTC by nunojob
Modified: 2014-05-20 16:54 UTC (History)
4 users (show)

See Also:


Attachments

Description nunojob 2010-05-21 11:05:02 UTC
define function local:foo($bar, $baz=fn:current-date-time()) { ... } ;

instead of

define function local:foo($bar) { local:foo($bar, 
fn:current-date-time())  } ;
define function local:foo($bar, $baz) { ... } ;
Comment 1 John Snelson 2010-05-21 13:17:21 UTC
I think this is an interesting future direction, since it will also allow users to safely define functions that take the context item as an implicit argument:

define function local:findIDs($node as node() := .)
{
  $node//@id
};

This kind of default argument is evaluated in the calling context, rather than the function's context.

That said, this is almost certainly a feature that should be considered for XQuery 1.2 rather than XQuery 1.1.
Comment 2 Jonathan Robie 2010-06-03 19:53:07 UTC
Polymorphism is already listed as a potential feature for future versions, as are generics:

Bug 9062

This is related to polymorphism, but you ask for defaults as well. I'd like to move this to future versions.
Comment 3 Michael Kay 2012-07-25 14:26:29 UTC
Renamed the requirement to emphasize its relatively modest ambitions; as described, this is simply a convenient way of defining a family of functions with the same name and different arity using fewer lines of code than currently needed.
Comment 4 John Snelson 2012-07-25 14:52:11 UTC
There's a little more to this feature request. Default arguments would be evaluated in the static and dynamic context of the caller, which would allow the definition of functions which took a default context item, for instance.
Comment 5 Michael Kay 2012-07-25 21:28:14 UTC
The static environment of the caller? So $x:var accesses different variables depending on the namespace binding of x? Surely not.
Comment 6 John Snelson 2012-07-26 10:55:38 UTC
Interesting point - this clearly needs more thought.

I do think it's reasonable to have a default argument of fn:default-collation() however, which is what I was thinking of when I said it should use the static context of the caller.
Comment 7 Jonathan Robie 2014-05-20 16:54:08 UTC
Assigning to future requirements per Working Group decision (https://lists.w3.org/Archives/Member/w3c-xsl-query/2012Oct/0087.html).