A list comprehension takes the form:
[where:
in
,
,
in
,
,
]
Note that, syntactically, the first element of a list comprehension, called a list constructor, takes the special form of T:(E in D). A list of this form is interpreted as a list comprehension in calls to '@='/2 and constraints in B-Prolog.
A list comprehension is treated as a foreach call with an accumulator. For example, the query L@=[(A,I) : A in [a,b], I in 1..2] is the same as
foreach(A in [a,b], I in 1..2, ac1(L,[]),L^0=[(A,I)|L^1]).