Re: references and dependency

I finally spent some time on this. My understanding is the following.

The purpose of the dependency graph is to support spreadsheet-like
dependencies between *values*. What we call a value is stored as the text
content of an XML element or the value of an XML attribute. [^typed-values]
In this way, XML elements are attributes act like cells in a spreadsheet.

Values are typically modified by form controls, but can also come from
other sources (the `setvalue` action, a `submission` with `replace="text"`,
a scripting API, etc.). In all cases they set/update XML text or attribute
values.

This notion of value excludes storing information as, say, a MIP, or as the
name of an attribute or element. We consider that the information captured
by the form consists of text-within-elements-or-attribute-values.

The dependency graph is created upon `rebuild`. It is fixed until the next
rebuild. The hope is that, in many cases, the graph doesn't need to be
rebuilt so that MIPs and calculated values can be evaluated quickly and, in
the case of calculated values, in dependency order (so that a sum is
computed after the parts of the sum are updated, for example). So in
general you are just modifying the value of cells in the spreadsheet.

When we do a `recalculate`, a dependency graph already exists (from the
previous `rebuild`). Here, the dependencies are on *values*, that is,
character content. So a discussion of recalculate must use this as the
definition of a dependency.

Now there is a more general notion of dependency. In particular, nodes
pointed to by the dependency graph with `<bind ref="...">` can *depend* on
character content but also on other aspects of the XML data model. The
sames goes with the result of a computed expression. A `setvalue`, an
`insert`, a `delete`, or a `submission` can cause the dependency graph to
be different if it is re-evaluated.

So XForms talks about these dependencies and, specifically, dynamic
dependencies, only to explain that there are changes to the data model
which can make the dependency graph obsolete, in which case it should be
rebuilt, or subsequent `recalculate` and `revalidate` will produce
incorrect results. This can be done explicitly with a `rebuild` action or
implicitly as part of `insert` or `delete`.

I am not sure that it is very useful to cover all the details of what
changes to the data model can affect the result of an expression, or to
make a distinction between nodes which are referenced or not during
expression evaluation. This can even depend on how optimized an XPath
processor might be.

It should be enough to say that there are expressions with dynamic
dependencies, provide examples, and indicate that manual rebuilds are
needed in such cases.

By the way, it is certainly possible to improve on the above. For example,
allowing MIPs to be part of the dependency graph would be useful.

-Erik

[^typed-values]: With XPath 2, it can be also be a *typed value*. A typed
value also comes from the text content so that doesn't make a difference
for this discussion.


On Wed, Jan 25, 2017 at 4:12 AM, Steven Pemberton <steven.pemberton@cwi.nl>
wrote:

> There is some duplication of definitions.
>
> Recalculate
> defines 'reference' 'dependent' 'circular dependency'
> https://www.w3.org/community/xformsusers/wiki/XForms_2.0#Recalculate
>
> Expressions > References, Dependencies, and Dynamic Dependencies
> defines 'references' 'dependent' 'dynamically dependent'
> https://www.w3.org/community/xformsusers/wiki/
> XForms_2.0#References.2C_Dependencies.2C_and_Dynamic_Dependencies
>
> So I plan to bring these together, and merge them.
>
> However, the latter section distinguishes dependency for computed
> expressions and other expressions. In particular a computed expression has
> to use the content of a node to be dependent on it, while other expressions
> are dependent on it regardless.
>
> "A computed expression is *dependent* on an instance node if it references
> it and uses its character content (rather than just referencing for
> navigation); any other expression is dependent on an instance node if it
> just references it."
>
> Recalculate doesn't make this distinction.
>
> Which is right?
>
> Steven
>
>

Received on Wednesday, 8 February 2017 00:05:50 UTC