<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29627</bug_id>
          
          <creation_ts>2016-05-15 18:42:32 +0000</creation_ts>
          <short_desc>Appendix examples eg:highest, eg:lowest - proposed improvement</short_desc>
          <delta_ts>2016-07-21 14:06:53 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Functions and Operators 3.1</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Hans-Juergen Rennau">hrennau</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>126437</commentid>
    <comment_count>0</comment_count>
    <who name="Hans-Juergen Rennau">hrennau</who>
    <bug_when>2016-05-15 18:42:32 +0000</bug_when>
    <thetext>The current examples assume a value getter function which maps an item to exactly one atomic value. In practise, typical candidates for such a value getter more often than not may also produce the empty sequence, for example due to the rare but not impossible absence of some XML element or attribute.

Please consider making the example a little more realistic by assuming a value getter function with this signature:
   function(item()) as xs:anyAtomicType?

The implementation of eg:higest, for example, might then look like this:

declare function eg:highest(
                     $seq as item()*, 
                     $getValue as function(item()) as xs:anyAtomicType?)
                 as item()* {
  fold-left(
    $seq,
    (),
    function($highestSoFar as item()*, $item as item()) as item()* {
      let $value := $getValue($item)
      let $highestValue := $highestSoFar[1] ! $getValue(.)
      return
        if (empty($value)) then $highestSoFar
        else if ($value &gt; $highestValue or empty($highestSoFar)) then $item
        else if ($value = $highestValue) then ($highestSoFar, $item)
        else $highestSoFar
      }
  )
};</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126479</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-05-23 11:51:38 +0000</bug_when>
    <thetext>These functions are provided as examples. I&apos;m reluctant to do work on them that is justified only because people might want to use them to solve a real problem that is different from the requirement they currently address. Indeed, one of the reasons that some of these functions were put in an appendix as examples of user-written functions, rather than putting them into the spec as core functions, was that we recognized there might be a variety of user requirements and it would be hard for a single function to satisfy them all.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126556</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-05-24 15:38:07 +0000</bug_when>
    <thetext>The WG agreed with the reasoning in comment #1 and decided to take no action. There&apos;s plenty of scope for publishing useful example functions outside the W3C specification.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>