> 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.
>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. > It takes *time* to get into the functional way of thinking @Christian. I agree, this is another way of thinking, and I am surely not experienced with it, since I started a month ago. But I have here a basic problem, and I think that there is no answer : I don't know how to work with a stack or a vector with xquery. It means that I will have to bind xquery to JAVA if I need to work extensively with these data structures. > that it’s possible to build efficient data structures with functional languages @Christian. Yes it is. So we are back to my previous question : why these data structures are not shipped as standard XQUERY for vectors or stacks handling, as maps are ? 2013/12/3 John Snelson <[email protected]> > On 03/12/13 11:27, jean-marc Mercier wrote: > >> > XQuery comes from the world of database >> I understand this point. From another side, it could be used to write >> complex algorithmic : I found this language very handy to that purpose, >> because it is a functional language, it is incredibly data flexible, and >> template programming is straightforward. Provided basic containers were >> added, the community could enrich this language with external modules, >> best among them could in turn feed the standardization process. At >> present time, as far as I understand, the only way to write a serious >> algorithm is to bind XQUERY with an external imperative language, that >> is not really a good solution. >> > > You can create a simple linked list using a cons cell: > > declare function local:cons($head,$tail) > { > function() { $head, $tail } > }; > > declare function local:to-list($seq) > { > if(empty($seq)) then () else > local:cons(head($seq),local:to-list(tail($seq))) > > }; > > John > > -- > John Snelson, Lead Engineer http://twitter.com/jpcs > MarkLogic Corporation http://www.marklogic.com > _______________________________________________ > [email protected] > http://x-query.com/mailman/listinfo/talk >
_______________________________________________ [email protected] http://x-query.com/mailman/listinfo/talk
