Perfect. Feel free to check out XQuery 3.1 as well:
http://docs.basex.org/wiki/XQuery_3.1
On Fri, Oct 23, 2015 at 3:53 PM, Ron Katriel rkatriel@mdsol.com wrote:
Hi Cristian,
I tried the nested for loops below and it performed as expected (monotonically increasing count).
There are a a lot of great enhancements in XQuery 3.0. Thanks for pointing that out!
Thanks, Ron
for $n in (1 to 10)[. mod 2 = 1] for $m in (1 to 10)[. mod 2 = 0] count $c return <number count="{ $c }" odd="{ $n }" even="{ $m }"/>
On October 23, 2015 at 9:36:35 AM, Christian Grün (christian.gruen@gmail.com) wrote:
Hi Ron,
Out of interest: did you have a look at the "count" clause [1]?
Christian
[1] http://docs.basex.org/wiki/XQuery_3.0#Enhanced_FLWOR_Expressions
On Fri, Oct 23, 2015 at 12:02 AM, Ron Katriel rkatriel@mdsol.com wrote:
Thanks all!
I went with the solution suggested by Christian. It is simple, efficient, and solves my problem (starting at 1 is fine). The GFLWOR approach is nice, except that I have two nested for loops so it produces two counts instead of one (and there is no straightforward way to combine them into a single monotonically increasing number).
Best, Ron
On October 22, 2015 at 5:47:53 AM, Marc van Grootel (marc.van.grootel@gmail.com) wrote:
Hi,
Wouldn't clj-ds [1] be of any help in this? It has support for transients.I believe that Exist uses this somewhere in their code not sure where. I think it makes use of these Atomic* objects under the hood but providing a "functional" facade. btw I'm not speaking from experience with this library but I do have it on my longlist.
On Thu, Oct 22, 2015 at 9:38 AM, Christian Grün christian.gruen@gmail.com wrote:
Hi Rob,
A short variant of your approach could look like this:
import module namespace counter = 'java.util.concurrent.atomic.AtomicInteger'; for $i in 1 to 10 return counter:incrementAndGet()
As you already indicated, it violates the functional programming design, so I would surely recommend everyone to use the GFLWOR "at" or "count" clause (or possibly fold-left, etc.)
And hi Ron,
Do you need to start with an existing counter when running your query, or is it sufficient to start with 1?
Christian
On Thu, Oct 22, 2015 at 9:07 AM, Rob Stapper r.stapper@lijbrandt.nl wrote:
Hi Ron,
Maybe the attached codes-nippet is useful to you. It is an example of stateful programming, which isn't compliant with the functional programming concept but, in some cases, can be very useful.
Hopes it helps, Rob Stapper
PS. put the module-file in a subdirectory: "counter", in your basex-repo-directory.
-- --Marc