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 22302 - The equivalent code for fn:for-each() is incorrect.
Summary: The equivalent code for fn:for-each() is incorrect.
Status: RESOLVED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.0 (show other bugs)
Version: Working drafts
Hardware: PC Windows NT
: P2 minor
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-06 18:20 UTC by Nicolae Brinza
Modified: 2013-06-09 21:33 UTC (History)
0 users

See Also:


Attachments

Description Nicolae Brinza 2013-06-06 18:20:08 UTC
In the current working draft of XQuery F&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))
Comment 1 Michael Kay 2013-06-09 21:33:05 UTC
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).