<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Ahh, I see what you mean now.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I guess everyone does it the same, and that is if a QName comes after the arrow, it is a function call and the argument can be placed right away. If a variable ref or parenthesis expression come after, they need to be resolved first, and then the argument set.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Wrapping the map:for-each call in parenthesis does the trick there by forcing the RHS to resolve before the Arrow.  <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>function($k, $v) {<o:p></o:p></p><p class=MsoNormal>    "$k=" || $k<o:p></o:p></p><p class=MsoNormal>} =><o:p></o:p></p><p class=MsoNormal>(<o:p></o:p></p><p class=MsoNormal>  map:for-each(<o:p></o:p></p><p class=MsoNormal>      map {<o:p></o:p></p><p class=MsoNormal>          "a" : "1",<o:p></o:p></p><p class=MsoNormal>          "b" : "2",<o:p></o:p></p><p class=MsoNormal>          "c" : "3"<o:p></o:p></p><p class=MsoNormal>      },<o:p></o:p></p><p class=MsoNormal>      ?<o:p></o:p></p><p class=MsoNormal>  )<o:p></o:p></p><p class=MsoNormal>)()   <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Makes me also wonder though if partial functions should be resolved first. Interesting!<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><b>From:</b> talk-bounces@x-query.com <talk-bounces@x-query.com> <b>On Behalf Of </b>Adam Retter<br><b>Sent:</b> Montag, 11. März 2019 07:45<br><b>To:</b> Zachary N. Dean <contact@zadean.com><br><b>Cc:</b> talk@x-query.com; juri@existsolutions.com<br><b>Subject:</b> Re: [xquery-talk] Arrow Operator to a Partially Applied Function<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>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...<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>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.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>On Mon, 11 Mar 2019, 13:37 Zachary N. Dean, <<a href="mailto:contact@zadean.com">contact@zadean.com</a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm'><p class=MsoNormal style='margin-bottom:12.0pt'>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">talk-bounces@x-query.com</a> <<a href="mailto:talk-bounces@x-query.com" target="_blank">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">talk@x-query.com</a>><br>Cc: <a href="mailto:juri@existsolutions.com" target="_blank">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" 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" 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" target="_blank">http://www.adamretter.org.uk</a><br>_______________________________________________<br><a href="mailto:talk@x-query.com" target="_blank">talk@x-query.com</a><br><a href="http://x-query.com/mailman/listinfo/talk" 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" target="_blank">https://www.avg.com</a><o:p></o:p></p></blockquote></div></div></div><div id=DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2><p class=MsoNormal><o:p> </o:p></p><table class=MsoNormalTable border=1 cellpadding=0 style='border:none;border-top:solid #D3D4DE 1.0pt'><tr><td width=55 style='width:41.25pt;border:none;padding:9.75pt .75pt .75pt .75pt'><p class=MsoNormal><a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><span style='text-decoration:none'><img border=0 width=46 height=29 style='width:.4791in;height:.302in' id="_x0000_i1025" src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png"></span></a><o:p></o:p></p></td><td width=470 style='width:352.5pt;border:none;padding:9.0pt .75pt .75pt .75pt'><p class=MsoNormal style='line-height:13.5pt'><span style='font-size:10.0pt;font-family:"Arial",sans-serif;color:#41424E'>Virus-free. <a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><span style='color:#4453EA'>www.avg.com</span></a> <o:p></o:p></span></p></td></tr></table><p class=MsoNormal><o:p> </o:p></p></div></div></body></html>