RE: lazy or eager variable initialization? [qt-2004Feb1090-01]

> 
> Michael Kay wrote:
> 
> >>declare variable $x { $y };
> >>declare variable $y { 10 };
> >>$x + $y
> >>
> 
> So the question remains:  is the example portable,
> implementation-defined, or neither?

I had lost track slightly of WG decisions in this area, but the current
internal draft, which I believe correctly reflects decisions made by the WG,
makes this an error. It states:

[Definition: If a variable declaration includes an expression, the
expression is called an initializing expression.] Initializing expressions
are evaluated at the beginning of the dynamic evaluation phase. The static
context for an initializing expression includes all functions that are
declared or imported anywhere in the Prolog, but it includes only those
variables and namespaces that are declared or imported earlier in the Prolog
than the variable that is being initialized. If an initializing expression
cannot be evaluated because of a circularity (for example, it depends on a
function that in turn depends on the value of the variable that is being
initialized), a dynamic error is raised.[err:XQ0054]

In XSLT the corresponding construct is legal: XSLT allows forwards
references to global variables. Another difference is that XSLT gives the
implementation the choice of reporting circularities as static or dynamic
errors.

I'm going to have to update Saxon's XQuery implementation so that this
example stops working...

Michael Kay

Received on Wednesday, 23 June 2004 23:19:09 UTC