<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Ah - it's a precedence problem. Try putting the partial apply in parentheses:</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">function($k, $v) {<br>
    "$k=" || $k<br>
} =><br>
    <a class="moz-txt-link-freetext" href="map:for-each(">(map:for-each(</a><br>
        map {<br>
            "a" : "1",<br>
            "b" : "2",<br>
            "c" : "3"<br>
        },<br>
        ?<br>
    ))()</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">John<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 11/03/2019 10:22, John Snelson wrote:<br>
</div>
<blockquote type="cite" cite="mid:97783c4a-841a-b301-5f8d-006e780a55d0@marklogic.com">
<div class="moz-cite-prefix">Looks like a bug to me. The first argument of the partially applied
<a class="moz-txt-link-rfc2396E" href="map:for-each" moz-do-not-send="true">"map:for-each"</a> is the one marked with a "?".<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 10/03/2019 23:45, Adam Retter wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAPK0icj2=xih5Qpa54cpToP9h1vbqAtE=VDkvhiSVVETYcfK1A@mail.gmail.com">
<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" moz-do-not-send="true">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>
    <a class="moz-txt-link-freetext" href="map:for-each(" moz-do-not-send="true">
map:for-each(</a><br>
        map {<br>
            "a" : "1",<br>
            "b" : "2",<br>
            "c" : "3"<br>
        },<br>
        ?<br>
    )()<br>
<br>
Simply becomes:<br>
<br>
 <a class="moz-txt-link-freetext" href="map:for-each(" moz-do-not-send="true">map:for-each(</a><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 <a class="moz-txt-link-freetext" href="map:for-each" moz-do-not-send="true">
map:for-each</a> 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" moz-do-not-send="true">
talk-bounces@x-query.com</a> <<a href="mailto:talk-bounces@x-query.com" target="_blank" rel="noreferrer" moz-do-not-send="true">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" moz-do-not-send="true">talk@x-query.com</a>><br>
Cc: <a href="mailto:juri@existsolutions.com" target="_blank" rel="noreferrer" moz-do-not-send="true">
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] <a class="moz-txt-link-freetext" href="map:for-each(map,function)" moz-do-not-send="true">
map:for-each(map,function)</a>: 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" moz-do-not-send="true">http://www.w3.org/2005/xpath-functions/map</a>";<br>
<br>
function($k, $v) {<br>
    "$k=" || $k<br>
} =><br>
    <a class="moz-txt-link-freetext" href="map:for-each(" moz-do-not-send="true">
map:for-each(</a><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 <a class="moz-txt-link-freetext" href="map:for-each" moz-do-not-send="true">
map:for-each</a> 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" moz-do-not-send="true">http://www.w3.org/2005/xpath-functions/map</a>";<br>
<br>
let $x :=<br>
    <a class="moz-txt-link-freetext" href="map:for-each(" moz-do-not-send="true">
map:for-each(</a><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" moz-do-not-send="true">http://www.adamretter.org.uk</a><br>
_______________________________________________<br>
<a href="mailto:talk@x-query.com" target="_blank" rel="noreferrer" moz-do-not-send="true">talk@x-query.com</a><br>
<a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer noreferrer" target="_blank" moz-do-not-send="true">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" moz-do-not-send="true">https://www.avg.com</a><br>
<br>
</blockquote>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
<a class="moz-txt-link-abbreviated" href="mailto:talk@x-query.com" moz-do-not-send="true">talk@x-query.com</a>
<a class="moz-txt-link-freetext" href="http://x-query.com/mailman/listinfo/talk" moz-do-not-send="true">http://x-query.com/mailman/listinfo/talk</a></pre>
</blockquote>
<p><br>
</p>
<pre class="moz-signature" cols="72">-- 
John Snelson, Principal Engineer              <a class="moz-txt-link-freetext" href="http://twitter.com/jpcs" moz-do-not-send="true">http://twitter.com/jpcs</a>
MarkLogic Corporation                         <a class="moz-txt-link-freetext" href="http://www.marklogic.com" moz-do-not-send="true">http://www.marklogic.com</a></pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
<a class="moz-txt-link-abbreviated" href="mailto:talk@x-query.com">talk@x-query.com</a>
<a class="moz-txt-link-freetext" href="http://x-query.com/mailman/listinfo/talk">http://x-query.com/mailman/listinfo/talk</a></pre>
</blockquote>
<p><br>
</p>
<pre class="moz-signature" cols="72">-- 
John Snelson, Principal Engineer              <a class="moz-txt-link-freetext" href="http://twitter.com/jpcs">http://twitter.com/jpcs</a>
MarkLogic Corporation                         <a class="moz-txt-link-freetext" href="http://www.marklogic.com">http://www.marklogic.com</a></pre>
</body>
</html>