Module sequence

This module is inspired by SQL query options such as TOP. Providing such a module was recently pioneered by SWI-Prolog. Currently predicates limit/2 and offset/2 are provided. The predicates solely work tuple oriented and it is possible to cascade these predicates:

Example:
?- limit(5, offset(3, between(1, 10, X))).
X = 4 ;
X = 5 ;
X = 6 ;
X = 7 ;
X = 8

The current implementation is based on call_nth/2, which is also provided through this module. call_nth/2 is in turn implemented with pivots, an alternative to nb_setarg/3 which does not destruct a Prolog term, but instead a Java object.

The following sequence predicates are provided:

limit(C, G):
The predicate succeeds whenever the goal G succeeds but limits the number of solutions to C.
offset(C, G):
The predicate succeeds whenever the goal G succeeds except for the first C solutions which are suppressed.
call_nth(G, C):
The predicate succeeds whenever G succeeds and unifies C with the numbering of the successes.

Kommentare