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

2019-03-11 Thread Zachary N. Dean
Ahh, I see what you mean now.

 

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.

 

Wrapping the map:for-each call in parenthesis does the trick there by forcing 
the RHS to resolve before the Arrow.  

 

 

function($k, $v) {

"$k=" || $k

} =>

(

  map:for-each(

  map {

  "a" : "1",

  "b" : "2",

  "c" : "3"

  },

  ?

  )

)()   

 

Makes me also wonder though if partial functions should be resolved first. 
Interesting!

 

 

 

From: talk-boun...@x-query.com  On Behalf Of Adam 
Retter
Sent: Montag, 11. März 2019 07:45
To: Zachary N. Dean 
Cc: talk@x-query.com; j...@existsolutions.com
Subject: Re: [xquery-talk] Arrow Operator to a Partially Applied Function

 

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

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

 


 
<http://www.avg.com/email-signature?utm_medium=email_source=link_campaign=sig-email_content=emailclient>
 

Virus-free.  
<http://www.avg.com/email-signature?utm_medium=email_source=link_campaign=sig-email_content=emailclient>
 www.avg.com 

 

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

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

2019-03-11 Thread Zachary N. Dean
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  On Behalf Of Adam
Retter
Sent: Montag, 11. März 2019 06:21
To: XQuery Talk ML 
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