Discussion:
[xquery-talk] Is this a valid query?
Adam Retter
2016-01-10 19:30:08 UTC
Permalink
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
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Michael Kay
2016-01-10 21:51:48 UTC
Permalink
There's an open bug against the spec on the use of ?-placeholders in conjunction with the arrow operator.

https://www.w3.org/Bugs/Public/show_bug.cgi?id=29346

The grammar allows it, but the semantics have not been specified.

My own view is that

X => map:for-each(A, ?)

should mean

map:for-each(X, A, ?)

which is an error because there are too many arguments.

But we need to await the WG decision on this bug.

Michael Kay
Saxonica
Post by Adam Retter
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
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
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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Adam Retter
2016-01-10 22:03:41 UTC
Permalink
Thanks Mike, that is exactly the kinda detail I needed, and the bug
report has many good comments.

Personally I do like the idea and syntax from an XQuery authoring
perspective of being able to do:

X => map:for-each(A, ?) meaning map:for-each(A, X)

However, I am not precious about it. So whichever way it is decided,
as long as the spec defines, I will be both happy and informed ;-)

Thanks again. Adam.
Post by Michael Kay
There's an open bug against the spec on the use of ?-placeholders in conjunction with the arrow operator.
https://www.w3.org/Bugs/Public/show_bug.cgi?id=29346
The grammar allows it, but the semantics have not been specified.
My own view is that
X => map:for-each(A, ?)
should mean
map:for-each(X, A, ?)
which is an error because there are too many arguments.
But we need to await the WG decision on this bug.
Michael Kay
Saxonica
Post by Adam Retter
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
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
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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
--
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
James Fuller
2016-01-10 22:07:16 UTC
Permalink
+1 for

X => map:for-each(A, ?) meaning map:for-each(A, X)

Jim Fuller
Post by Adam Retter
Thanks Mike, that is exactly the kinda detail I needed, and the bug
report has many good comments.
Personally I do like the idea and syntax from an XQuery authoring
X => map:for-each(A, ?) meaning map:for-each(A, X)
However, I am not precious about it. So whichever way it is decided,
as long as the spec defines, I will be both happy and informed ;-)
Thanks again. Adam.
Post by Michael Kay
There's an open bug against the spec on the use of ?-placeholders in
conjunction with the arrow operator.
Post by Michael Kay
https://www.w3.org/Bugs/Public/show_bug.cgi?id=29346
The grammar allows it, but the semantics have not been specified.
My own view is that
X => map:for-each(A, ?)
should mean
map:for-each(X, A, ?)
which is an error because there are too many arguments.
But we need to await the WG decision on this bug.
Michael Kay
Saxonica
Post by Adam Retter
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
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
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
_______________________________________________
http://x-query.com/mailman/listinfo/talk
--
Adam Retter
skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Loading...