Bill Allombert on Tue, 18 Sep 2012 14:43:46 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

iterator interface


Dear PARI developers,

There is an ongoing discussion on pari-users on the subject of new iterators
like forprime/forcomposite/forprimepowers.
So maybe we should extend the description system to cover iterators in a more
straightforward way.

The current 2.6 interface looks like (since last week...)
  {
    GEN p;
    forprime_t primepointer; 
    forprime_init(&primepointer, gen_1, stoi(100));;
    while ((p = forprime_next(&primepointer)))
      pari_printf("%Ps\n", p);
  }
So for each iterators that conforms to this model we need:
1) a type (forprime_t)
2) an init function (forprime_init)
3) a next function  (forprime_next)
We need a description for each of them and furthermore we can provide variants depending
on the type of the loop index.  As a result we need 6 descriptions just for
forprime (see src/functions/programming/forprime).

To avoid hard-coding everything, iterators could have an extra description field:
Iterator: (forprime_t,_forprime_init,_forprime_next)

However we need to define the calling convention for _forprime_init/_forprime_next
(not for the matching C functions!).

Some suggestion:
1) We could use a single type for all iterators to make thing simpler (we get
rid of forprime_t).
2) We could merge the description of the variants in a single description, by adding
  the type of the loop index as an argument.
3) We could try to make forvec fit in this scheme.

Cheers,
Bill.