A list comprehension takes the form:
aa aaa aaa aaa aaa aaa aaa [T : E1 in D1,where the optional LocalVars specifies a list of local variables, and the optional Goal must be a callable term. The construct means that, for each combination of values, En in Dn, LocalVars,Goal]
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 in 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]).