[ Control | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic Index ]

fork(+Max, -I)

Succeeds for all integers I between 1 and Max. The solutions are generated in parallel.
Max
Integer
I
Variable or Integer

Description

Generates in parallel the integers between 1 and a given maximum Max. The order of solutions is unspecified. For every value of Max, this predicate behaves as if defined by

   :- parallel fork/2.
   fork(Max, Max).
   ...
   fork(Max, 2).
   fork(Max, 1).
Operationally, the advantage of fork/2 compared to a recursive definition like

   :- parallel bfork/2.
   bfork(Max, Max).
   bfork(Max, I) :- Max>1, Max1 is Max-1, bfork(Max1, I).
is that fork/2 creates only a single wide choice point instead of Max binary ones. This improves efficiency, especially for parallel execution.

Modes and Determinism

Fail Conditions

Fails if Max is less than 1

Exceptions

(4) instantiation fault
Max is not instantiated.
(5) type error
Max is not an integer.

Examples

% peclipse -w 3
[eclipse 1]: fork(5,X), get_flag(worker, W).
X = 5
W = 1     More? (;)
X = 3
W = 3     More? (;)
X = 4
W = 2     More? (;)
X = 2
W = 1     More? (;)
X = 1
W = 3     More? (;)
no (more) solution.



See Also

between / 4, parallel / 1, repeat / 0, get_flag / 2