[xquery-talk] Arrow Operator to a Partially Applied Function
Michael Kay
mike at saxonica.com
Mon Mar 11 10:33:16 PDT 2019
> On 11 Mar 2019, at 17:22, John Snelson <John.Snelson at marklogic.com> wrote:
>
> Looks like a bug to me. The first argument of the partially applied "map:for-each" <map:for-each> is the one marked with a "?".
Not sure what you mean by "bug" here, but I think it's doing what the spec says.
A => B(x, ?)()
means
B(A, x, ?)()
not
B(x, ?)(A)
Michael Kay
Saxonica
>
> On 10/03/2019 23:45, Adam Retter wrote:
>> Thanks Zach. I suspect you are right. However I can't help wishing that the argument placeholders should be resolved before the arrow operator is applied...
>>
>> For the average developer, the fact that my first query raises an error seems non intuitive, especally in light of the reformulation in my second query.
>>
>> On Mon, 11 Mar 2019, 13:37 Zachary N. Dean, <contact at zadean.com <mailto:contact at zadean.com>> wrote:
>> Hello Adam,
>>
>> I think the issue is that the Arrow Operator '=>' is simply "syntactic
>> sugar" for using the LHS as the FIRST argument of the function call on the
>> RHS.
>> The Argument Placeholder '?' has no direct relation to the Arrow Operator.
>>
>> So, in the case of the first example:
>>
>> function($k, $v) {
>> "$k=" || $k
>> } =>
>> map:for-each( <map:for-each(>
>> map {
>> "a" : "1",
>> "b" : "2",
>> "c" : "3"
>> },
>> ?
>> )()
>>
>> Simply becomes:
>>
>> map:for-each( <map:for-each(>
>> function($k, $v) {
>> "$k=" || $k
>> },
>> map {
>> "a" : "1",
>> "b" : "2",
>> "c" : "3"
>> },
>> ?
>> )()
>>
>>
>> So, the 3 argument map:for-each <map:for-each> isn't found. (and the final call would have
>> the wrong arity if it was found)
>>
>>
>> Hope this helps,
>>
>> Zack
>>
>> -----Original Message-----
>> From: talk-bounces at x-query.com <mailto:talk-bounces at x-query.com> <talk-bounces at x-query.com <mailto:talk-bounces at x-query.com>> On Behalf Of Adam
>> Retter
>> Sent: Montag, 11. März 2019 06:21
>> To: XQuery Talk ML <talk at x-query.com <mailto:talk at x-query.com>>
>> Cc: juri at existsolutions.com <mailto:juri at existsolutions.com>
>> Subject: [xquery-talk] Arrow Operator to a Partially Applied Function
>>
>> Without thinking too deeply, whilst writing some XQuery recently I was
>> initially surprised to discover that the following (simplified) query fails
>> with the static error - [XPST0017] map:for-each(map,function) <map:for-each(map,function)>: 3 arguments
>> supplied, 2 expected.
>>
>>
>> xquery version "3.1";
>> declare namespace map = "http://www.w3.org/2005/xpath-functions/map <http://www.w3.org/2005/xpath-functions/map>";
>>
>> function($k, $v) {
>> "$k=" || $k
>> } =>
>> map:for-each( <map:for-each(>
>> map {
>> "a" : "1",
>> "b" : "2",
>> "c" : "3"
>> },
>> ?
>> )()
>>
>>
>> After having looked into the specs in more detail, I thought I was able to
>> derive a reason for this... i.e. the partial function application syntax is
>> not processed until the dynamic evaluation phase. Therefore when the arrow
>> operator is processed first during the static analysis phase, it tries to
>> find a map:for-each <map:for-each> function that takes 3 parameters, the first being of the
>> function type on LHS of the arrow operator, and second being the map, and
>> the third being the unbound parameter `?`.
>>
>> However, I then noticed that if I reformulatedby query with an indirection
>> through a variable binding `$x` then it compiles and executes just fine.
>> Presumably this indicates that my understanding above is incorrect, as
>> whilst the variable binding may change the evaluation order, the static
>> analysis and dynamic evaluation phases should still happen in the same
>> order.
>>
>>
>> xquery version "3.1";
>> declare namespace map = "http://www.w3.org/2005/xpath-functions/map <http://www.w3.org/2005/xpath-functions/map>";
>>
>> let $x :=
>> map:for-each( <map:for-each(>
>> map {
>> "a" : "1",
>> "b" : "2",
>> "c" : "3"
>> },
>> ?
>> )
>> return
>>
>> function($k, $v) {
>> "$k=" || $k
>> } => $x()
>>
>>
>> I basically get the same results on eXist-db, Saxon, and BaseX. I would
>> appreciate if someone could help me understand what I am seeing here...
>>
>> Thanks Adam.
>>
>> --
>> Adam Retter
>>
>> skype: adam.retter
>> tweet: adamretter
>> http://www.adamretter.org.uk <http://www.adamretter.org.uk/>
>> _______________________________________________
>> talk at x-query.com <mailto:talk at x-query.com>
>> http://x-query.com/mailman/listinfo/talk <http://x-query.com/mailman/listinfo/talk>
>>
>> ---
>> This email has been checked for viruses by AVG.
>> https://www.avg.com <https://www.avg.com/>
>>
>>
>>
>> _______________________________________________
>> talk at x-query.com <mailto:talk at x-query.com>
>> http://x-query.com/mailman/listinfo/talk <http://x-query.com/mailman/listinfo/talk>
> --
> John Snelson, Principal Engineer http://twitter.com/jpcs <http://twitter.com/jpcs>
> MarkLogic Corporation http://www.marklogic.com <http://www.marklogic.com/>_______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20190311/c5a09e99/attachment.html>
More information about the talk
mailing list