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.

[1]: https://github.com/krukow/clj-ds

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