<div dir="auto"><div>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...</div><div dir="auto"><br></div><div dir="auto">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.</div><div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Mon, 11 Mar 2019, 13:37 Zachary N. Dean, <<a href="mailto:contact@zadean.com">contact@zadean.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Adam,<br>
<br>
I think the issue is that the Arrow Operator '=>' is simply "syntactic<br>
sugar" for using the LHS as the FIRST argument of the function call on the<br>
RHS.<br>
The Argument Placeholder '?' has no direct relation to the Arrow Operator.<br>
<br>
So, in the case of the first example:<br>
<br>
function($k, $v) {<br>
    "$k=" || $k<br>
} =><br>
    map:for-each(<br>
        map {<br>
            "a" : "1",<br>
            "b" : "2",<br>
            "c" : "3"<br>
        },<br>
        ?<br>
    )()<br>
<br>
Simply becomes:<br>
<br>
 map:for-each(<br>
    function($k, $v) {<br>
        "$k=" || $k<br>
    },<br>
     map {<br>
         "a" : "1",<br>
         "b" : "2",<br>
         "c" : "3"<br>
     },<br>
     ?<br>
 )()<br>
<br>
<br>
So, the 3 argument map:for-each isn't found. (and the final call would have<br>
the wrong arity if it was found)<br>
<br>
<br>
Hope this helps,<br>
<br>
Zack<br>
<br>
-----Original Message-----<br>
From: <a href="mailto:talk-bounces@x-query.com" target="_blank" rel="noreferrer">talk-bounces@x-query.com</a> <<a href="mailto:talk-bounces@x-query.com" target="_blank" rel="noreferrer">talk-bounces@x-query.com</a>> On Behalf Of Adam<br>
Retter<br>
Sent: Montag, 11. März 2019 06:21<br>
To: XQuery Talk ML <<a href="mailto:talk@x-query.com" target="_blank" rel="noreferrer">talk@x-query.com</a>><br>
Cc: <a href="mailto:juri@existsolutions.com" target="_blank" rel="noreferrer">juri@existsolutions.com</a><br>
Subject: [xquery-talk] Arrow Operator to a Partially Applied Function<br>
<br>
Without thinking too deeply, whilst writing some XQuery recently I was<br>
initially surprised to discover that the following (simplified) query fails<br>
with the static error - [XPST0017] map:for-each(map,function): 3 arguments<br>
supplied, 2 expected.<br>
<br>
<br>
xquery version "3.1";<br>
declare namespace map = "<a href="http://www.w3.org/2005/xpath-functions/map" rel="noreferrer noreferrer" target="_blank">http://www.w3.org/2005/xpath-functions/map</a>";<br>
<br>
function($k, $v) {<br>
    "$k=" || $k<br>
} =><br>
    map:for-each(<br>
        map {<br>
            "a" : "1",<br>
            "b" : "2",<br>
            "c" : "3"<br>
        },<br>
        ?<br>
    )()<br>
<br>
<br>
After having looked into the specs in more detail, I thought I was able to<br>
derive a reason for this... i.e. the partial function application syntax is<br>
not processed until the dynamic evaluation phase. Therefore when the arrow<br>
operator is processed first during the static analysis phase, it tries to<br>
find a map:for-each function that takes 3 parameters, the first being of the<br>
function type on LHS of the arrow operator, and second being the map, and<br>
the third being the unbound parameter `?`.<br>
<br>
However, I then noticed that if I reformulatedby query with an indirection<br>
through a variable binding `$x` then it compiles and executes just fine.<br>
Presumably this indicates that my understanding above is incorrect, as<br>
whilst the variable binding may change the evaluation order, the static<br>
analysis and dynamic evaluation phases should still happen in the same<br>
order.<br>
<br>
<br>
xquery version "3.1";<br>
declare namespace map = "<a href="http://www.w3.org/2005/xpath-functions/map" rel="noreferrer noreferrer" target="_blank">http://www.w3.org/2005/xpath-functions/map</a>";<br>
<br>
let $x :=<br>
    map:for-each(<br>
        map {<br>
            "a" : "1",<br>
            "b" : "2",<br>
            "c" : "3"<br>
        },<br>
        ?<br>
    )<br>
return<br>
<br>
  function($k, $v) {<br>
      "$k=" || $k<br>
  } => $x()<br>
<br>
<br>
I basically get the same results on eXist-db, Saxon, and BaseX. I would<br>
appreciate if someone could help me understand what I am seeing here...<br>
<br>
Thanks Adam.<br>
<br>
--<br>
Adam Retter<br>
<br>
skype: adam.retter<br>
tweet: adamretter<br>
<a href="http://www.adamretter.org.uk" rel="noreferrer noreferrer" target="_blank">http://www.adamretter.org.uk</a><br>
_______________________________________________<br>
<a href="mailto:talk@x-query.com" target="_blank" rel="noreferrer">talk@x-query.com</a><br>
<a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer noreferrer" target="_blank">http://x-query.com/mailman/listinfo/talk</a><br>
<br>
---<br>
This email has been checked for viruses by AVG.<br>
<a href="https://www.avg.com" rel="noreferrer noreferrer" target="_blank">https://www.avg.com</a><br>
<br>
</blockquote></div></div></div>