Re: [xquery-talk] Looping in Xquery
You're close - the missing part is that you want to use the sum() function, ie: short-desc{ sum( for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition return string-length($shrtdesc/p/text) ) }/short-desc John On 04/09/12 10:15, Mailing Lists Mail wrote: Dear Xquery Adults, I am very new here.. I have some issues with getting my requirements working.. I guess, this should be very simple, but dont seem to get my heads around... THe following is what I want.. I have loads of XMLs in the Data Store ( markLogic) I have to run a query to do the return the string lengths of certain elements from 100 XMLs./ So my pseudo code will be : results For all XMLs in the Data store { file filename = filename of the current file desc {length of desc at //xx/y/desc } !-- There could be more than one desc, in which case, i would like the sum of all the string lengths of each desc -- /desc short-desc { string-length ( //xx//yy/short-desc) } /short-desc /file /results My attempts: declare namespace dict = http://www.lexis-nexis.com/glp/dict;; for $ltnfiles in doc() let $NAME:= document-uri($ltnfiles) return ( ltn name {$NAME} /name short-desc {string-length(string($ltnfiles//subtopic[@id = 'DEF']/short-definition/p/text))} /short-desc /ltn ) THe above works fine, if there is only one short-definition.. FOr more than one shortdefiitions, it comes up with the error message obviously because the string does not allow 2 arguments, while the stuff passed into the function is a sequence... How do I do another loop inside the first one, for each short-defiitin ... SOmething like : for $ltnfiles in doc() let $NAME:= document-uri($ltnfiles) return ( ltn name {$NAME} /name { for $shrtdesc in $ltnfiles//subtopic[@id = 'DEF']//short-definition short-desc { string-length( $shrtdesc/p/text) } /short-desc } /ltn ) DOEstNT WORK .. :( This wont give me what I want as What I want is a sum (string-lengths of all the short-def) .. But atleast i thought i would get something like short-desc100/short-desc short-desc344/short-desc ( I would have liked short-desc444/short-desc ) ANy help would be highly appreciated .. Thanks Dak. -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] map module for XQUERY ?
The following libraries are written in pure XQuery 3.0: rbtree.xq - https://github.com/jpcs/rbtree.xq Functional implementation of a red/black tree (ordered set) that allows a custom implementation of the comparison function. See the included map.xq for how this can be used to implement a map data structure using lt comparison. Should be easy to implement an alternative map that allows node keys with a suitable comparison function. hamt.xq - https://github.com/jpcs/hamt.xq Functional implementation of a hash array mapped trie (hash set) that allows a custom hash function and equality function. See the included hashmap.xq for how this can be used to implement a map data structure. Hope that helps, John On 20/11/13 09:43, jean-marc Mercier wrote: Hello, I am looking for a map module in XQUERY that would have the following behavior. Does somebody ever heard of such a module ? 1) The default behavior for inserting keys should be using the fn:distinct-values(). Note that map module using this mechanism already exists, see for instance BaseX map:module : http://docs.basex.org/wiki/Map_Module 2) Accept functions as values. Why this could be useful ? Well, it is really useful for a lot of things. The first very useful things would be to use this functionality to bind external parameters to functions. For instance I could write, (useful for the point 3) below) declare function local:is_data1_smaller_than_data2($data1,$data2,$map_bindings){ map:get($map_bindings,less)($data1,$data2) }; 3) Accept an optional, external ordering predicate. This is actually what is done with every structured languages. For instance, set in C++ (that are indeed maps) are defined as template class T,// set::key_type/value_type */_class Compare = lessT_/*,// set::key_compare/value_compare class Alloc = allocatorT // set::allocator_type class set; where the ordering predicate is optional (*/_class Compare = lessT). _/*Why having an optional ordering predicate could be useful in ? Because of point 4) below : to use node() as keys in map. 4) Accept node() as keys. This is very useful to a lot of things. However, it does not exists a canonical ordering for nodes. The function deep-equal() could be a candidate, but it does not define an ordering, and performances in insertion using this function would be tremendous. Thus, to accept node() as keys for maps, one need first to provide an external ordering predicate for nodes, see point 3) above. -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] map module for XQUERY ?
On 20/11/13 13:16, jean-marc Mercier wrote: ok. I've done a first draft that is working. I will keep the code a little bit to tune and complete it. For instance, that could be an idea to implement the remove($map,$key) function, or to implement key($map). Implenting keys($map) can be done using the fold() function. I recall the remove() algorithm being a fair amount harder to implement in a functional red/black tree, and I didn't need it so I didn't tackle it. However, I have to modify your rbtree to do it. Very happy to accept contributions of a remove() implementation if you do it. :-) John -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] map module for XQUERY ?
This conversation should probably move to personal email or the github issue tracker. This isn't a bug, it's by design. If it didn't work this way you'd never be able to replace a key that already existed in a map. John On 21/11/13 07:56, jean-marc Mercier wrote: @John Hello. I started modifying your RB tree. I noticed that, while inserting two time the same keys, the last inserted value replace the previous one into your rbtree. As an illustration the following query let $map := map:new( (map:entry(dummy,rocks),map:entry(dummy,roll)) ) return map:get($map,dummy) returns roll I was expecting to rocks. First : can you reproduce it ? (I modified your files, and use BaseX interpretor. It is better to check with another implementation). Second, should I roll your rbtree or is this expected (is this a bug or not ?) ? 2013/11/20 jean-marc Mercier jeanmarc.merc...@gmail.com mailto:jeanmarc.merc...@gmail.com Yes you're right, using fold should be strightfroward. For the remove function, I'll try. Hopefully I won't spent too much time :) I'll keep you posted 2013/11/20 John Snelson john.snel...@marklogic.com mailto:john.snel...@marklogic.com On 20/11/13 13:16, jean-marc Mercier wrote: ok. I've done a first draft that is working. I will keep the code a little bit to tune and complete it. For instance, that could be an idea to implement the remove($map,$key) function, or to implement key($map). Implenting keys($map) can be done using the fold() function. I recall the remove() algorithm being a fair amount harder to implement in a functional red/black tree, and I didn't need it so I didn't tackle it. However, I have to modify your rbtree to do it. Very happy to accept contributions of a remove() implementation if you do it. :-) John -- John Snelson, Lead Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] [xml-dev] OT: Suggestion for new OSS SCC site / tool for xmlsh ? SourceForge has gone to the dark side.
Github's pretty good - I used this to become familiar with Git (your life will get better ;-)): http://ftp.newartisans.com/pub/git.from.bottom.up.pdf The main issue I have is it's lack of release management support. And yes, unlike HTML 5 I do believe having release checkpoints benefits users. :-) With a dig at HTML 5, I think this thread is now back on topic, right? John On 25/11/2013 14:42, Michael Sokolov wrote: On 11/25/2013 09:23 AM, David Lee wrote: I am so annoyed by this thread and the associated links which seem to clear the FUD http://www.gluster.org/2013/08/how-far-the-once-mighty-sourceforge-has-fallen/ ... Do I need (want to?) learn git ? and move to github ? My Git experience so far has been disappointing (I cant figure it out ! The model makes no sense and I never know if stuff is checked in or not) I have some projects on google code which has been sufficient and trustworthy as sites go ... but it has that google owns you creepiness factor. David, I researched these options a year or so ago and concluded it was time to learn git/github; however lack of good support for hosting large binaries kind of forces you to host those elsewhere. Google code seems like the other main option. I wonder if there isn't a possibility SF will right the ship, though? About git: you can use git more-or-less like svn, although there are definitely extra steps. One thing I have come to really like about it is the ability to commit changes without immediately sharing them with the world (you commit, and then push, as two steps). You could do this with svn branches, kind of, but they seem so heavyweight and I never really use them as much as perhaps I should. I do find myself searching stackoverflow every so often when I get into weird git situations. -Mike ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] map module for XQUERY ?
On 03/12/13 12:17, jean-marc Mercier wrote: You can create a simple linked list using a cons cell: @John : Right, but you will always have quadratic complexity in length creating the sequence $seq. Not always. But that was just example code - don't create it from a sequence. I can only speculate, because we haven’t seen your implementation, but I am wondering why you didn’t take advantage of John’s existing $lessthan function argument in order to compare all kinds of items? @ Christian. Indeed, I realized after profiling my rewriting of John code that its code implementation has also a quadratic complexity in sequence length. John, as I, need at a point to allocate memory for writing this tree implementation. If we want to stay pure xquery, this will be done with quadratic complexity in length, at least I can't see any work around to that. My red/black tree implementation only ever uses sequences of length 4, which will therefore have a constant cost to create (in the size of the red/black tree). John -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] XQuery 3.0 Grouping - Sufficiently baffled by ordering
On 07/01/14 12:39, Michael Kay wrote: Yes, I was surprised to see that a let clause isn't allowed after an order-by or group-by. I don't remember the reasons for that. A let clause _can_ be used after an order by or group by clause in XQuery 3.0: http://www.w3.org/TR/xquery-30/#prod-xquery30-FLWORExpr I suspect this is just unimplemented in eXist. John -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] Tales of the unexpected version III - Atomization
On 08/01/14 16:25, Ihe Onwuka wrote: On Wed, Jan 8, 2014 at 4:22 PM, David Carlisle dav...@nag.co.uk mailto:dav...@nag.co.uk wrote: On 08/01/2014 15:38, Ihe Onwuka wrote: because it is going to end up (by whatever process) as an attribute node. That seems to be the cause of your confusion (and your misreading of the spec and Mike Kay's book) Ok. What sections of Mike Kay's book Mike Kay's book doesn't cover XQuery. and the spec didn't I read that conveyed the information you just gave and what references to them did I miss. http://www.w3.org/TR/xquery-30/#id-content John -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] Tales of the unexpected version III - Atomization
In the XQuery 3.0 specification, section 3.9.1 describes direct element constructors. A sub-section inside that (3.9.1.3 Content) describes how to process the content of direct element constructors. This section is also linked from 3.9.3.1 Computed Element Constructors. http://www.w3.org/TR/xquery-30/#id-content The XQuery spec is not always straight forward to read, but I think it's clear in this case. However the XQuery spec is not meant to be a tutorial in XQuery - there are better places to learn XQuery. John On 08/01/14 16:39, Ihe Onwuka wrote: and that referenced from section 2.4.2 where? or was I supposed to have sussed that from seeing * Constructor expressions for various kinds of nodes if I wasI guess it's my bad. On Wed, Jan 8, 2014 at 4:29 PM, John Snelson john.snel...@marklogic.com mailto:john.snel...@marklogic.com wrote: On 08/01/14 16:25, Ihe Onwuka wrote: On Wed, Jan 8, 2014 at 4:22 PM, David Carlisle dav...@nag.co.uk mailto:dav...@nag.co.uk mailto:dav...@nag.co.uk mailto:dav...@nag.co.uk wrote: On 08/01/2014 15:38, Ihe Onwuka wrote: because it is going to end up (by whatever process) as an attribute node. That seems to be the cause of your confusion (and your misreading of the spec and Mike Kay's book) Ok. What sections of Mike Kay's book Mike Kay's book doesn't cover XQuery. and the spec didn't I read that conveyed the information you just gave and what references to them did I miss. http://www.w3.org/TR/xquery-__30/#id-content http://www.w3.org/TR/xquery-30/#id-content John -- John Snelson, Lead Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com _ talk@x-query.com mailto:talk@x-query.com http://x-query.com/mailman/__listinfo/talk http://x-query.com/mailman/listinfo/talk -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] Izzit Bcos I is functional?
On 16/06/15 08:21, Ihe Onwuka wrote: Probably the wrong place to ask but what are the prime factors behind the resistance to adopt XQuery or it's derivatives thereof as a technology for querying and manipulating semi-structured data. What can you say about why any programming language becomes popular? There are too many counter examples to believe it's because of technical merit, or that they solve problems better or that others can't. The only answer is that programming is subject to fashions and trends beyond logical understanding. It's an unsatisfactory answer, but it's the only one. John -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] Empty or Null Array?
On 16/07/2015 10:29, Eliot Kimber wrote: I do see that I can do: let $array := [()] To create an array with one member that is an empty sequence. My business problem is I need to pass an array of sequences to a recursive function, where each recursion takes the cadr of the array. When the array is empty, recursion stops. So the question is, how to determine that an array is empty given that an array must have at least one member. It looks like the answer is an array is empty when the only member is an empty sequence. Is my analysis correct? No. The grammar is this: [73] ArrayConstructorhttp://www.w3.org/TR/xpath-31/#prod-xpath31-ArrayConstructor ::= SquareArrayConstructorhttp://www.w3.org/TR/xpath-31/#doc-xpath31-SquareArrayConstructor | CurlyArrayConstructorhttp://www.w3.org/TR/xpath-31/#doc-xpath31-CurlyArrayConstructor [74] SquareArrayConstructorhttp://www.w3.org/TR/xpath-31/#prod-xpath31-SquareArrayConstructor ::= [ (ExprSinglehttp://www.w3.org/TR/xpath-31/#doc-xpath31-ExprSingle (, ExprSinglehttp://www.w3.org/TR/xpath-31/#doc-xpath31-ExprSingle)*)? ] [75] CurlyArrayConstructorhttp://www.w3.org/TR/xpath-31/#prod-xpath31-CurlyArrayConstructor ::= array { Exprhttp://www.w3.org/TR/xpath-31/#doc-xpath31-Expr? } The SquareArrayConstructor has parentheses and a ? operator around the exprSingles inside it, so they are optional and can be left out. Thus you can use [] for an empty array. Similarly the CurlyArrayConstructor for a ? on it's Expr so it can be left out. Thus you can also use array{} for an empty array. John -- John Snelson, Lead Engineerhttp://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] Error when using predicate after arrow operator
The equivalence holds for how it functionally behaves, not for what grammar the parser allows. You need parentheses: ("1.2.3" => tokenize("\."))[. < "3"] John On 13/04/2017 20:09, Joe Wicentowski wrote: > Hi all, > > As I understand the arrow operator > (https://www.w3.org/TR/xquery-31/#id-arrow-operator), the following > query: > >"1.2.3" => tokenize("\.") > > is equivalent to: > > tokenize("1.2.3", "\.") > > If this is so, then can anyone shed light on why appending a predicate > to the former would raise an error but not so for the latter? In > Saxon, eXist, and BaseX, the following expression: > >"1.2.3" => tokenize("\.")[. < "3"] > > raises an error like: > >XPST0003: Unexpected token "[" beyond end of query > > whereas the pre-XQuery 3.1 approach: > > tokenize("1.2.3", "\.")[. < "3"] > > returns the results I'd expect: > >("1", "2") > > Thanks, > Joe > ___ > talk@x-query.com > http://x-query.com/mailman/listinfo/talk -- John Snelson, Principal Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] tail recursive identity transformation
I don't think you can do a tail recursive tree walk of an XDM tree - you at least need a stack of the path taken to a particular node in order to process first it's children, and then it's following siblings. You could track the stack as an accumulating argument to the recursive call, but it may just be easier and more readable to use the function call stack. Additionally when constructing a result tree, I think most XQuery implementations will need to generate an "end tag" after the recursive call - which will mean the recursive call won't be at the "tail" at all. It's probably possible to optimize this case specifically - but again it will entail the implementation keeping track of constructed elements that still need to be closed in some kind of stack. John On 15/09/17 11:55, Kendall Shaw wrote: > I was trying to do something like: > > def id(e: List[Int], acc: List[Int]): List[Int] = > if (e.isEmpty) > acc.reverse > else > id(e.tail, e.head :: acc) > > or > > > > > > > > But, I didn't figure how to pass anything analogous to "head" of an > element, or analagous to . > > If you can give an example of a tail recursive identity transformation > in XQuery that would be helpful to me. > > Kendall > > > On 09/15/2017 02:23 AM, Michael Kay wrote: >> I'm very confused by this. The function body contains two recursive >> calls. The one inside the typeswitch is certainly not tail-recursive, >> so you're going to get recursion depth equal to the maximum tree >> depth. The other call, as far as I can see, merely returns its second >> argument unchanged, which seems totally pointless. >> >> Michael Kay >> Saxonica >> >>> On 15 Sep 2017, at 09:30, Kendall Shaw <ks...@kendallshaw.com> wrote: >>> >>> I don't remember seeing an xquery function that tries to return it's >>> input unchanged. >>> >>> Can this be improved: >>> >>> declare function local:id($e as element()?, $acc as element()?) as >>> element() { >>>if (empty($e)) then >>> $acc >>> else >>> local:id(() >>> , element {node-name($e)} { >>>$e/@* >>>, for $node in $e/node() >>> return typeswitch($node) >>> case element() return local:id($node, $acc) >>> default return $node >>> }) >>> }; >>> >>> The idea is that functions that do more than return their input >>> could be based on the function, and benefit from tail call >>> optimization. >>> >>> Kendall >>> >>> >>> ___ >>> talk@x-query.com >>> http://x-query.com/mailman/listinfo/talk >> >> ___ >> talk@x-query.com >> http://x-query.com/mailman/listinfo/talk >> >> > > ___ > talk@x-query.com > http://x-query.com/mailman/listinfo/talk -- John Snelson, Principal Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] Arrow Operator to a Partially Applied Function
Looks like a bug to me. The first argument of the partially applied "map:for-each" is the one marked with a "?". On 10/03/2019 23:45, Adam Retter wrote: 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 ___ talk@x-query.com<mailto:talk@x-query.com> http://x-query.com/mailman/listinfo/talk -- John Snelson, Principal Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk
Re: [xquery-talk] Arrow Operator to a Partially Applied Function
Ah - it's a precedence problem. Try putting the partial apply in parentheses: function($k, $v) { "$k=" || $k } => (map:for-each( map { "a" : "1", "b" : "2", "c" : "3" }, ? ))() John On 11/03/2019 10:22, John Snelson wrote: Looks like a bug to me. The first argument of the partially applied "map:for-each" is the one marked with a "?". On 10/03/2019 23:45, Adam Retter wrote: 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 ___ talk@x-query.com<mailto:talk@x-query.com> http://x-query.com/mailman/listinfo/talk -- John Snelson, Principal Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com<mailto:talk@x-query.com> http://x-query.com/mailman/listinfo/talk -- John Snelson, Principal Engineer http://twitter.com/jpcs MarkLogic Corporation http://www.marklogic.com ___ talk@x-query.com http://x-query.com/mailman/listinfo/talk