[xquery-talk] Arrow Operator to a Partially Applied Function

Adam Retter adam.retter at googlemail.com
Sun Mar 10 23:45:24 PDT 2019


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> 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 {
>             "a" : "1",
>             "b" : "2",
>             "c" : "3"
>         },
>         ?
>     )()
>
> Simply becomes:
>
>  map:for-each(
>     function($k, $v) {
>         "$k=" || $k
>     },
>      map {
>          "a" : "1",
>          "b" : "2",
>          "c" : "3"
>      },
>      ?
>  )()
>
>
> So, the 3 argument 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 <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>
> Cc: 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): 3 arguments
> supplied, 2 expected.
>
>
> xquery version "3.1";
> declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
>
> function($k, $v) {
>     "$k=" || $k
> } =>
>     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 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";
>
> let $x :=
>     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
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
>
> ---
> This email has been checked for viruses by AVG.
> https://www.avg.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20190311/263fb86a/attachment.html>


More information about the talk mailing list