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-boun...@x-query.com <talk-boun...@x-query.com> On Behalf Of Adam
Retter
Sent: Montag, 11. März 2019 06:21
To: XQuery Talk ML <talk@x-query.com>
Cc: j...@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@x-query.com
http://x-query.com/mailman/listinfo/talk

---
This email has been checked for viruses by AVG.
https://www.avg.com


_______________________________________________
talk@x-query.com
http://x-query.com/mailman/listinfo/talk

Reply via email to