Hi Jorge, Henrik,

On Tue, May 29, 2012 at 11:26:42AM +0700, Henrik Sarvell wrote:
> More complicated (but prettier) would be a later -> wait combo (if
> possible in your situation):

Yes, I would also say that 'later' / 'wait' is the way to go. But as I
understood Jorge, he wants to do something with (a subset of) all
database objects of a given (single) database.

In the general case, I would select those objects with a 'pilog'
expression, and then process them with 'later'. If -- as in Jorge's
question -- all objects are desired, I'd use 'iter' to directly iterate
a tree:

   (de processCustomers (N . Prg)
      (let Lst (need N)
         (iter (tree 'nr '+CuSu)
            '((This)
               (let Pos (wait NIL (memq NIL Lst))
                  (set Pos T)
                  (later Pos
                     (run Prg)
                     NIL ) ) ) ) ) )

I've tested it in the demo 'app'

   $ ./pil app/main.l lib/too.l -main +
   ...
   : (processCustomers 5 (msg This) (wait 500))
   {2-1}
   {2-5}
   ...

The 'Lst' variable holds a list of the desired length, initialized to
all 'NIL' elements.

Then all customer objects are iterated, using the 'nr' number index.

'memq' finds the next free slot, and points 'Pos' to it. 'set' marks
that slot with 'T', then 'later' starts to do the work in 'Prg'. Finally
the 'later' body returns 'NIL', to mark that slot as "free" again.

(Note that for a general solution (e.g. in a library), it is recommended
to use transient symbols for all involved parameters and variables)

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to