<?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>6217</bug_id>
          
          <creation_ts>2008-11-11 16:09:25 +0000</creation_ts>
          <short_desc>[FO11] Stable, contexual, deterministic, non-deterministic</short_desc>
          <delta_ts>2009-11-06 18:53:13 +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>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</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="Jonathan Robie">jonathan.robie</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          <cc>jim.melton</cc>
    
    <cc>jmdyck</cc>
    
    <cc>zhen.liu</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>22409</commentid>
    <comment_count>0</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2008-11-11 16:09:25 +0000</bug_when>
    <thetext>The relationship between stable, contextual, deterministic, and non-deterministic is not spelled out, and the terms stable and contextual, though carefully defined, are confusing and not used much outside of the definitions. 

This raises some questions.

1) Are all functions stable unless the text says 
otherwise? If not, then how do I identify which functions are stable?

2) Only two functions are said to be contextual. 
Are these the only ones? If not, then how do I identify which are contextual?

3) Contextual is defined in the definition of 
stable. What is the relationship between 
contextual functions and stable functions. Can a function be both?

4) We need to address whether unordered is 
non-deterministic, unstable, or both.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25300</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2009-05-26 09:43:05 +0000</bug_when>
    <thetext>I don&apos;t think the term &quot;non-deterministic&quot; is useful in F+O, and it&apos;s hardly used. &quot;implementation-dependent&quot; is all we need.

Let&apos;s try:

A function may have the property of being contextual: the result of such a function depends on the values of properties in the static and dynamic evaluation context as well as on the actual supplied arguments (if any).

Functions that depend on the context fall into a number of categories:

(a) current-date(), current-dateTime(), current-time(), implicit-timezone(), adjust-date-to-timezone(), adjust-dateTime-to-timezone(), and adjust-time-to-timezone() depend on properties of the dynamic context that are fixed for the duration of a query or transformation. The same applies to a number of functions in the op: namespace that manipulate dates and times and that make use of the implicit timezone. These functions will return the same result if called repeatedly during a single query or transformation.

(b) position(), last(), id(), idref(), element-with-id(), lang(), local-name(), name(), namespace-uri(), normalize-space(), number(), root(), string(), string-length() depend on the focus. These functions will in general return different results on different calls if the focus is different.

(c) default-collation() and many string-handling operators and functions depend on the default collation and the in-scope collations, which are both properties of the static context. If a particular call of one of these functions is evaluated twice with the same arguments then it will return the same result each time (because the static context, by definition, does not change at run time). However, two distinct calls (that is, two calls on the function appearing in different places in the source code) may produce different results even if the explicit arguments are the same.

(d) Functions such as static-base-uri(), doc(), and collection() depend on other aspects of the static context. As with functions that depend on collations, a single call will produce the same results on each call if the explicit arguments are the same, but two calls appearing in different places in the source code may produce different results.

For a contextual function, the parts of the context on which it depends are referred to below as implicit arguments.

Two values $V and $W are defined to be identical if ... [Odd that we don&apos;t have a definition of this. It&apos;s easy enough to define for nodes and atomic values, harder now that we have first-class functions in the data model].

A function that is guaranteed to produce identical results from repeated calls if the explicit and implicit arguments are identical is referred to as *stable*.

All functions defined in this specification are stable unless otherwise stated. Exceptions include the following:

* Some functions (distinct-values, unordered) produce results in an implementation-defined order. In such cases there is no guarantee that the order of results from different calls will be the same. These functions are said to be ordering-unstable. [Is this what we want? Or do we want the results of these functions to be stable?]

* The function analyze-string (introduced in 2.1) constructs an element node to represent its results. There is no guarantee that repeated calls with the same arguments will return the same identical node (in the sense of the &quot;is&quot; operator). Such a function is said to be identity-unstable.

* Some functions (doc, collection) create new nodes by reading external documents. Such functions are guaranteed to be stable with the exception that an implementation is allowed to mke them unstable as a user option.

Where the results of a function are described as being (to a greater or lesser extent) implementation-defined or implementation-dependent, this does not by itself remove the requirement that the results should be stable: that is, that repeated calls with the same explicit and implicit arguments should return identical results.

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25311</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2009-05-26 17:46:50 +0000</bug_when>
    <thetext>&gt; If a particular call of one of these functions is evaluated twice
&gt; with the same arguments then it will return the same result each time
&gt; (because the static context, by definition, does not change at run time).

I think the parenthetical clause will be slightly clearer if we say
    ... the static context of the call ...
or
    ... the static context of an expression ...
(at which point, I think the &quot;by definition&quot; would fit better after the &quot;because&quot;.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25831</commentid>
    <comment_count>3</comment_count>
    <who name="zhen hua liu">zhen.liu</who>
    <bug_when>2009-06-30 15:49:44 +0000</bug_when>
    <thetext>need to consider the scope of &apos;query&apos; or &apos;transformation&apos; for stablity of F&amp;O
with respect to xquery scripting:
current-date(), current-dateTime(), current-time(), implicit-timezone(),
adjust-date-to-timezone(), adjust-dateTime-to-timezone(), and
adjust-time-to-timezone() that depend on properties of the dynamic context that are
fixed for the duration of a query or transformation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25832</commentid>
    <comment_count>4</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2009-06-30 15:56:32 +0000</bug_when>
    <thetext>The WG decided that we want to resolve this as suggested by  Mike Kay in Comment #1.

He may make editorial changes as needed.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>