<?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>22302</bug_id>
          
          <creation_ts>2013-06-06 18:20:08 +0000</creation_ts>
          <short_desc>The equivalent code for fn:for-each() is incorrect.</short_desc>
          <delta_ts>2013-06-09 21:33:05 +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.0</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Nicolae Brinza">nbrinza</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>88836</commentid>
    <comment_count>0</comment_count>
    <who name="Nicolae Brinza">nbrinza</who>
    <bug_when>2013-06-06 18:20:08 +0000</bug_when>
    <thetext>In the current working draft of XQuery F&amp;O 3.0, the fn:for-each() function ( http://www.w3.org/TR/xpath-functions-30/#func-for-each ) has the following equivalent XQuery code:

declare function fn:for-each($seq, $f) {
  if (fn:empty($seq))
  then ()
  else $f(fn:head($seq)), fn:for-each(fn:tail($seq), $f)
};

Probably the parenthesis around the else branch have been omitted, and so this code will result in an infinite recursion for any input. The fix would be to change the line:

  else $f(fn:head($seq)), fn:for-each(fn:tail($seq), $f)

to: 

  else ($f(fn:head($seq)), fn:for-each(fn:tail($seq), $f))</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88983</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2013-06-09 21:33:05 +0000</bug_when>
    <thetext>Thanks, I have deemed this editorial and have fixed it (by adding parentheses as suggested).

There was also a typo in the XSLT version of the function (missing quotes).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>