[xquery-talk] Is this a valid query?

Adam Retter adam.retter at googlemail.com
Sun Jan 10 11:30:08 PST 2016


Given this valid XQuery (1):

map:for-each(
    map {
        "a" : "1",
        "b" : "2",
        "c" : "3"
    },
    ?
)(function($k, $v) {
    "$k=" || $k
})

I am wondering, if rewriting it to the following form results in a
valid query with the same execution result (2):

function($k, $v) {
    "$k=" || $k
} =>
    map:for-each(
        map {
            "a" : "1",
            "b" : "2",
            "c" : "3"
        },
        ?
    )()

In my mind it does, however I can't find a current implementation
(eXist, BaseX, Saxon-EE) which will execute it, I guess this is due to
evaluation order of the expressions (although I get parser errors).

If I add some brackets to (2), to add precedence to the evaluation
order so that I have (3):

function($k, $v) {
    "$k=" || $k
} =>
    (
    map:for-each(
        map {
            "a" : "1",
            "b" : "2",
            "c" : "3"
        },
        ?
    ))()


Then it does seem to execute on BaseX and Saxon, but it feels like I
shouldn't need to add the brackets and that (2) should work! Can
someone add some comment/insight for me as to whether the XQuery spec
requires these brackets to make the parse and execution correct?
Somehow, I can't see it at the moment...


Thanks Adam.

-- 
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk


More information about the talk mailing list