static or dynamic binding of focus?

[This is a reposting of a message sent to www-xml-query-comments
on April 22.  However, there was never a response, and this is
a rather critical issue.]

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.

To use a concrete example, 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
incompatible with static typing.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/

Received on Wednesday, 5 June 2002 12:26:51 UTC