- From: Per Bothner <per@bothner.com>
- Date: Mon, 22 Apr 2002 15:04:46 -0700
- To: www-xml-query-comments@w3.org
- CC: per@bothner.com
It seems to me that the definition of the context item, size, position, and document in the Formal Semantics is inconsistent with that in the other documents. This may be a known issue, but I haven't seen it mentioned. The Formal Semantics defines path expressions so that the variables $fs:dot, $fs:position, and $fs:last get set. However, these variables are *lexical* variables that are defined using 'let' clauses. However, the Functions and Operators document defines (for example) position() as "an unsignedInt indicating the position of the context item within the sequence of items currently being processed". This implifies that the position is part of the dynamic state, not just the static state. The question I have is whether the following is (intended to be) well-defined: define function is-mid() { return position() == last() / 2 } document("foo.xml")/book/chapter[is-mid()] According to the Formal Semantics document, this gets re-written so that lexical variable $fs:position would be defined, such that the predicate is-mid() is the scope of the variable. Thus the invocation of position() in the body of is-mid is within the *dynamic* scope of the $fs:position variable. However, it is not within the *lexical* scope of $fs:position. So I see three possibilities: (1) The value of position is bound dynamically, the Formal Semantics is wrong, and my example is well-defined. (2) The value of position is bound statically, the Formal Semantics is correct, and the Functions and Operators is wrong in talking about "context functions". Instead a "function" like position() is actually a macro (syntactic sugar), and my example is not definied. (3) The value of position is bound dynamically, both documents are correct, and my example is well-defined. A 'let' clauses creates a dynamic or "fluid" binding, rather than a lexical binding. This is consistent, and many scripting langauges use it - but it seems incompatile with static typing. -- --Per Bothner per@bothner.com http://www.bothner.com/per/
Received on Monday, 22 April 2002 18:04:53 UTC