Skip to content
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

[FO] Built-in function changes to support default values #70

Closed
rhdunn opened this issue Apr 12, 2021 · 1 comment · Fixed by #304
Closed

[FO] Built-in function changes to support default values #70

rhdunn opened this issue Apr 12, 2021 · 1 comment · Fixed by #304
Labels
Enhancement A change or improvement to an existing feature XQFO An issue related to Functions and Operators

Comments

@rhdunn
Copy link
Contributor

rhdunn commented Apr 12, 2021

This issue tracks the changes needed to the built-in functions to allow them to combine the declarations into a single definition with default parameter values.

The general approach to this is to make required arguments optional if they are for a function signature that is not the lowest argument count signature, and move any associated logic into the function.

array:subarray

  1. Change array:subarray/$length from xs:integer to xs:integer?.

Rules

Except in error cases, the result of the function is the value of the expression op:A2S($array) => fn:subsequence($start, $length) => op:S2A().

Error Conditions

A dynamic error is raised [err:FOAY0001] if $start is less than one or greater than array:size($array) + 1.

A dynamic error is raised [err:FOAY0002] if $length is not an empty sequence and is less than zero.

A dynamic error is raised [err:FOAY0001] if $length is not an empty sequence and $start + $length is greater than array:size($array) + 1.

fn:concat

This should be modified to use a sequence-variadic signature, either as a 1 parameter function (taking an xs:anyAtomicType* value, allowing 0 and 1 arguments), or a 3 parameter function with the last parameter having the type xs:anyAtomicType*.

fn:differences

The $options parameter should be moved to the end of the parameter list in order to make the function a map-variadic function when default values are applied. This then makes it possible to specify the collation argument using a keyword argument in addition to specifying options as keyword arguments.

fn:resolve-uri

  1. Change fn:resolve-uri/$base from node() to node()?.
- If the $base argument is not supplied,
+ If the $base argument is the empty sequence,

fn:subsequence

  1. Change fn:subsequence/$length from xs:double to xs:double?.

When $length is the empty sequence, this function returns:

$input[fn:round($start) le position()]

When $length is not the empty sequence, this function returns:

$input[fn:round($start) le position() 
         and position() lt fn:round($start) + fn:round($length)]

fn:substring

  1. Change fn:subsequence/$length from xs:double to xs:double?.

More specifically, when $length is not the empty sequence the function returns the characters in $value whose position $p satisfies:

fn:round($start) <= $p and $p < fn:round($start) + fn:round($length)

When $length is the empty sequence the function assumes that $length is infinite and thus returns the ·characters· in $value whose position $p satisfies:

fn:round($start) <= $p

fn:tokenize

  1. Change fn:tokenize/$pattern from xs:string to xs:string?.

If $pattern is the empty sequence, the $value argument is set to fn:normalize-space($value) and $pattern is set to ' '.

fn:unparsed-text / fn:unparsed-text-available

  1. Change fn:unparsed-text/$encoding from xs:string to xs:string?.
  2. Change fn:unparsed-text-available/$encoding from xs:string to xs:string?.

fn:unparsed-text-lines

  1. Change fn:unparsed-text-lines/$encoding from xs:string to xs:string?.

The result of the function is the same as the result of the expression fn:tokenize(fn:unparsed-text($href, $encoding), '\r\n|\r|\n')[not(position()=last() and .='')].

Collations

  1. Change fn:collation-key/$collation from xs:string to xs:string?.
  2. Change fn:compare/$collation from xs:string to xs:string?.
  3. Change fn:contains/$collation from xs:string to xs:string?.
  4. Change fn:contains-token/$collation from xs:string to xs:string?.
  5. Change fn:deep-equal/$collation from xs:string to xs:string?.
  6. Change fn:differences/$collation from xs:string to xs:string?.
  7. Change fn:distinct-values/$collation from xs:string to xs:string?.
  8. Change fn:ends-with/$collation from xs:string to xs:string?.
  9. Change fn:index-of/$collation from xs:string to xs:string?.
  10. Change fn:max/$collation from xs:string to xs:string?.
  11. Change fn:min/$collation from xs:string to xs:string?.
  12. Change fn:starts-with/$collation from xs:string to xs:string?.
  13. Change fn:substring-after/$collation from xs:string to xs:string?.
  14. Change fn:substring-before/$collation from xs:string to xs:string?.
  15. Change fn:uniform/$collation from xs:string to xs:string?.
  16. Change fn:unique/$collation from xs:string to xs:string?.

Passing the empty sequence to the $collation argument is equivalent to supplying the default collation to that argument.

@rhdunn rhdunn added XQFO An issue related to Functions and Operators Enhancement A change or improvement to an existing feature labels Sep 14, 2022
@ChristianGruen ChristianGruen added this to the QT 4.0 milestone Oct 14, 2022
@michaelhkay
Copy link
Contributor

I'm writing a detailed PR along these lines, but I'm handling collations differently; rather than allowing the supplied value to be an empty sequence, I'm defining the default as $collation := fn:default-collation().

But I agree that where the default is complex, as with the $encoding parameter of fn:unparsed-text(), the best solution is probably to allow () as a value, and make it the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A change or improvement to an existing feature XQFO An issue related to Functions and Operators
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants