<?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>10724</bug_id>
          
          <creation_ts>2010-09-24 15:45:18 +0000</creation_ts>
          <short_desc>[XPath30] Editorial: Examples for inline function closures</short_desc>
          <delta_ts>2011-09-10 18:33:31 +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>XPath 3.0</component>
          <version>Member-only Editors 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="Oliver Hallam">oliver</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>jim.melton</cc>
          
          <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>39295</commentid>
    <comment_count>0</comment_count>
    <who name="Oliver Hallam">oliver</who>
    <bug_when>2010-09-24 15:45:18 +0000</bug_when>
    <thetext>This also applies to XQuery 1.1

The last example in section 3.1.7 seeks to demonstrate that inline functions hold the values of any in-scope variables that they use:


This example creates an inline function that returns the xs:integer value 7, i.e.: the value of the variable $a from the scope of the inline function expression:
let $a := 7
return
let $f := function() { $a }
return
let $a := 8
return $f()


Firstly, The outer variable $a never has a value other than 7, so this is not a very good example.

Secondly the extra return expressions are not necessary in XQuery; they could be rewritten as &quot;,&quot;s in XPath.

Thirdly, there is an errant &quot;:&quot; in the text introducing this.

Fourthly, all the examples are introduced as creating inline functions.  They in fact create function items.

Finally, this example should probably just return the function, not evaluate it



I suggest the following example instead (Much neater examples can be created in XQuery!):


This example creates a sequence of function items each of which returns a different node from the default collection.

collection()/(let $a := . return function() { $a })</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>56615</commentid>
    <comment_count>1</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2011-09-10 18:33:31 +0000</bug_when>
    <thetext>Nice! I just added this to the internal Working Draft. Thanks for the great example.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>