Evaluation
Boolean Evaluation
Almost any expression can be used as an argument for boolean constructs such as filters, conditionals or logical operators. Due to the fact that an expression evaluates to a sequence of nodes, it is necessary to precisely define its evaluation to an boolean value.
The boolean function test maps sequence \(S\) to a boolean value:
- ) if \(S\) is a sequence with more than one element, the boolean value is true
- ) if \(S\) is a singleton value \(e\) and
- ) \(e\) of type boolean, then the boolean value is \(e\)
- ) otherwise the boolean value is true
- ) if \(S\) is an empty sequence, the boolean value is false
Processing Table
The evaluations of essential expressions whose evaluations could not be immediately apparent, are the focus of this section.
The semantic function eval maps an expression \(E\) and a context node \(o\), which is initially the input node, to a sequence of nodes, and is partially defined in the following table.
| language element | expression pattern \(E\) | eval(\(E\), \(o\)) (evaluation of \(E\) with context node \(o\)) eval(\(F\)) = eval(\(F\), \(o\)) for arbitrary \(F\) |
remark |
|---|---|---|---|
| self | _ |
return \(o\) | |
| scope expression | X, Y |
eval(X)return eval( Y) |
X,Y,Z \(=\) ((X,Y),Z) |
| path | X.Y |
let \(R\) be the empty sequence for every \(x\) in eval( X) do\(\;\;\;\)for every \(y\) in eval( Y, \(x\)) do\(\;\;\;\;\;\;\)include \(y\) in \(R\) return \(R\) |
X.Y.Z \(=\) ((X.Y).Z) |
| conditional | if (B) X Y |
if (test(eval(B))) then return eval(X)else return eval( Y) |
|
| filter | X?(Y) |
let \(R\) be the empty sequence for every \(x\) in eval( X) do\(\;\;\;\)if (test(eval( Y, \(x\)))) then include \(x\) in \(R\)return \(R\) |
|
| construction (object) | { p : X, ... } |
return { p : eval(X), ... } |
p is an identifier or string |
| ... dynamic property | { prop(X) : Y, ... } |
return { eval(X) : eval(Y), ... } |
X must evaluate to a string |
| ... embedding | { X, ... } |
return { properties(eval(X)), ... } |
X must evaluate to a singleton containing an object. properties(\(x\)) 'embeds' the properties of \(x\) into the enclosing object |