<s>
A	O
list	B-Language
comprehension	I-Language
is	O
a	O
syntactic	O
construct	O
available	O
in	O
some	O
programming	O
languages	O
for	O
creating	O
a	O
list	O
based	O
on	O
existing	O
lists	O
.	O
</s>
<s>
It	O
follows	O
the	O
form	O
of	O
the	O
mathematical	O
set-builder	B-Language
notation	I-Language
(	O
set	B-Language
comprehension	I-Language
)	O
as	O
distinct	O
from	O
the	O
use	O
of	O
map	O
and	O
filter	B-Application
functions	O
.	O
</s>
<s>
Consider	O
the	O
following	O
example	O
in	O
set-builder	B-Language
notation	I-Language
.	O
</s>
<s>
is	O
a	O
predicate	B-Algorithm
expression	O
acting	O
as	O
a	O
filter	B-Application
on	O
members	O
of	O
the	O
input	O
set	O
.	O
</s>
<s>
is	O
an	O
output	O
expression	O
producing	O
members	O
of	O
the	O
new	O
set	O
from	O
members	O
of	O
the	O
input	O
set	O
that	O
satisfy	O
the	O
predicate	B-Algorithm
expression	O
.	O
</s>
<s>
commas	O
separate	O
the	O
predicates	B-Algorithm
and	O
can	O
be	O
read	O
as	O
"	O
AND	O
"	O
.	O
</s>
<s>
A	O
list	B-Language
comprehension	I-Language
has	O
the	O
same	O
syntactic	O
components	O
to	O
represent	O
generation	O
of	O
a	O
list	O
in	O
order	O
from	O
an	O
input	O
list	O
or	O
iterator	O
:	O
</s>
<s>
An	O
optional	O
predicate	B-Algorithm
expression	O
.	O
</s>
<s>
And	O
an	O
output	O
expression	O
producing	O
members	O
of	O
the	O
output	O
list	O
from	O
members	O
of	O
the	O
input	O
iterable	O
that	O
satisfy	O
the	O
predicate	B-Algorithm
.	O
</s>
<s>
In	O
Haskell	B-Language
's	I-Language
list	B-Language
comprehension	I-Language
syntax	O
,	O
this	O
set-builder	B-Language
construct	O
would	O
be	O
written	O
similarly	O
,	O
as	O
:	O
</s>
<s>
Here	O
,	O
the	O
list	O
0	O
..	O
represents	O
,	O
x^	O
2>3	O
represents	O
the	O
predicate	B-Algorithm
,	O
and	O
2*x	O
represents	O
the	O
output	O
expression	O
.	O
</s>
<s>
List	B-Language
comprehensions	I-Language
give	O
results	O
in	O
a	O
defined	O
order	O
(	O
unlike	O
the	O
members	O
of	O
sets	O
)	O
;	O
and	O
list	B-Language
comprehensions	I-Language
may	O
generate	O
the	O
members	O
of	O
a	O
list	O
in	O
order	O
,	O
rather	O
than	O
produce	O
the	O
entirety	O
of	O
the	O
list	O
thus	O
allowing	O
,	O
for	O
example	O
,	O
the	O
previous	O
Haskell	B-Language
definition	O
of	O
the	O
members	O
of	O
an	O
infinite	O
list	O
.	O
</s>
<s>
The	O
existence	O
of	O
related	O
constructs	O
predates	O
the	O
use	O
of	O
the	O
term	O
"	O
List	B-Language
Comprehension	I-Language
"	O
.	O
</s>
<s>
The	O
SETL	B-Language
programming	I-Language
language	I-Language
(	O
1969	O
)	O
has	O
a	O
set	O
formation	O
construct	O
which	O
is	O
similar	O
to	O
list	B-Language
comprehensions	I-Language
.	O
</s>
<s>
The	O
computer	B-General_Concept
algebra	I-General_Concept
system	I-General_Concept
AXIOM	B-Language
(	O
1973	O
)	O
has	O
a	O
similar	O
construct	O
that	O
processes	O
streams	O
.	O
</s>
<s>
The	O
first	O
use	O
of	O
the	O
term	O
"	O
comprehension	O
"	O
for	O
such	O
constructs	O
was	O
in	O
Rod	O
Burstall	O
and	O
John	O
Darlington	O
's	O
description	O
of	O
their	O
functional	O
programming	O
language	O
NPL	B-Language
from	O
1977	O
.	O
</s>
<s>
Burstall	O
and	O
Darlington	O
's	O
work	O
with	O
NPL	B-Language
influenced	O
many	O
functional	O
programming	O
languages	O
during	O
the	O
1980s	O
,	O
but	O
not	O
all	O
included	O
list	B-Language
comprehensions	I-Language
.	O
</s>
<s>
An	O
exception	O
was	O
Turner	O
's	O
influential	O
,	O
pure	O
,	O
lazy	O
,	O
functional	O
programming	O
language	O
Miranda	B-Language
,	O
released	O
in	O
1985	O
.	O
</s>
<s>
The	O
subsequently	O
developed	O
standard	O
pure	O
lazy	O
functional	O
language	O
Haskell	B-Language
includes	O
many	O
of	O
Miranda	B-Language
's	O
features	O
,	O
including	O
list	B-Language
comprehensions	I-Language
.	O
</s>
<s>
In	O
Haskell	B-Language
,	O
a	O
monad	O
comprehension	O
is	O
a	O
generalization	O
of	O
the	O
list	B-Language
comprehension	I-Language
to	O
other	O
monads	O
in	O
functional	O
programming	O
.	O
</s>
<s>
Version	O
3.x	O
and	O
2.7	O
of	O
the	O
Python	O
language	O
introduces	O
syntax	O
for	O
set	B-Language
comprehensions	I-Language
.	O
</s>
<s>
Similar	O
in	O
form	O
to	O
list	B-Language
comprehensions	I-Language
,	O
set	B-Language
comprehensions	I-Language
generate	O
Python	O
sets	O
instead	O
of	O
lists	O
.	O
</s>
<s>
Racket	B-Operating_System
set	B-Language
comprehensions	I-Language
generate	O
Racket	B-Operating_System
sets	O
instead	O
of	O
lists	O
.	O
</s>
<s>
Version	O
3.x	O
and	O
2.7	O
of	O
the	O
Python	O
language	O
introduced	O
a	O
new	O
syntax	O
for	O
dictionary	B-Application
comprehensions	O
,	O
similar	O
in	O
form	O
to	O
list	B-Language
comprehensions	I-Language
but	O
which	O
generate	O
Python	O
instead	O
of	O
lists	O
.	O
</s>
<s>
Racket	B-Operating_System
hash	O
table	O
comprehensions	O
generate	O
Racket	B-Operating_System
hash	O
tables	O
(	O
one	O
implementation	O
of	O
the	O
Racket	B-Operating_System
dictionary	B-Application
type	O
)	O
.	O
</s>
<s>
The	B-Application
Glasgow	I-Application
Haskell	I-Application
Compiler	I-Application
has	O
an	O
extension	O
called	O
parallel	O
list	B-Language
comprehension	I-Language
(	O
also	O
known	O
as	O
zip-comprehension	O
)	O
that	O
permits	O
multiple	O
independent	O
branches	O
of	O
qualifiers	O
within	O
the	O
list	B-Language
comprehension	I-Language
syntax	O
.	O
</s>
<s>
Racket	B-Operating_System
's	O
comprehensions	O
standard	O
library	O
contains	O
parallel	O
and	O
nested	O
versions	O
of	O
its	O
comprehensions	O
,	O
distinguished	O
by	O
"	O
for	O
"	O
vs	O
"	O
for*	O
"	O
in	O
the	O
name	O
.	O
</s>
<s>
The	O
following	O
is	O
Racket	B-Operating_System
code	O
for	O
the	O
Haskell	B-Language
list	B-Language
comprehension	I-Language
examples	O
.	O
</s>
<s>
Like	O
the	O
original	O
NPL	B-Language
use	O
,	O
these	O
are	O
fundamentally	O
database	O
access	O
languages	O
.	O
</s>
<s>
is	O
conceptually	O
evaluated	O
as	O
a	O
series	O
of	O
"	O
steps	O
"	O
where	O
each	O
step	O
produces	O
a	O
list	O
and	O
the	O
next	O
step	O
applies	O
a	O
filter	B-Application
function	O
to	O
each	O
element	O
in	O
the	O
previous	O
step	O
's	O
output	O
.	O
</s>
<s>
In	O
XQuery	O
,	O
full	O
XPath	O
is	O
available	O
,	O
but	O
FLWOR	B-Language
statements	O
are	O
also	O
used	O
,	O
which	O
is	O
a	O
more	O
powerful	O
comprehension	O
construct	O
.	O
</s>
<s>
Here	O
the	O
XPath	O
//book	O
is	O
evaluated	O
to	O
create	O
a	O
sequence	O
(	O
aka	O
list	O
)	O
;	O
the	O
where	O
clause	O
is	O
a	O
functional	O
"	O
filter	B-Application
"	O
,	O
the	O
order	O
by	O
sorts	O
the	O
result	O
,	O
and	O
the	O
XML	O
snippet	O
is	O
actually	O
an	O
anonymous	B-General_Concept
function	I-General_Concept
that	O
builds/transforms	O
XML	O
for	O
each	O
element	O
in	O
the	O
sequence	O
using	O
the	O
'	O
map	O
 '	O
approach	O
found	O
in	O
other	O
functional	O
languages	O
.	O
</s>
<s>
So	O
,	O
in	O
another	O
functional	O
language	O
the	O
above	O
FLWOR	B-Language
statement	O
may	O
be	O
implemented	O
like	O
this	O
:	O
</s>
<s>
C#	B-Application
3.0	O
has	O
a	O
group	O
of	O
related	O
features	O
called	O
LINQ	B-Language
,	O
which	O
defines	O
a	O
set	O
of	O
query	O
operators	O
for	O
manipulating	O
object	O
enumerations	O
.	O
</s>
<s>
LINQ	B-Language
provides	O
a	O
capability	O
over	O
typical	O
list	B-Language
comprehension	I-Language
implementations	O
.	O
</s>
<s>
When	O
the	O
root	O
object	O
of	O
the	O
comprehension	O
implements	O
the	O
IQueryable	B-Language
interface	O
,	O
rather	O
than	O
just	O
executing	O
the	O
chained	O
methods	O
of	O
the	O
comprehension	O
,	O
the	O
entire	O
sequence	O
of	O
commands	O
are	O
converted	O
into	O
an	O
abstract	B-Data_Structure
syntax	I-Data_Structure
tree	I-Data_Structure
(	O
AST	O
)	O
object	O
,	O
which	O
is	O
passed	O
to	O
the	O
IQueryable	B-Language
object	O
to	O
interpret	O
and	O
execute	O
.	O
</s>
<s>
C++	O
does	O
not	O
have	O
any	O
language	O
features	O
directly	O
supporting	O
list	B-Language
comprehensions	I-Language
but	O
operator	O
overloading	O
(	O
e.g.	O
,	O
overloading	O
|	O
,	O
>>	O
,	O
>>=	O
)	O
has	O
been	O
used	O
successfully	O
to	O
provide	O
expressive	O
syntax	O
for	O
"	O
embedded	O
"	O
query	O
domain-specific	B-Language
languages	I-Language
(	O
DSL	O
)	O
.	O
</s>
<s>
Alternatively	O
,	O
list	B-Language
comprehensions	I-Language
can	O
be	O
constructed	O
using	O
the	O
erase-remove	B-Language
idiom	I-Language
to	O
select	B-Language
elements	O
in	O
a	O
container	O
and	O
the	O
STL	O
algorithm	O
for_each	O
to	O
transform	O
them	O
.	O
</s>
<s>
There	O
is	O
some	O
effort	O
in	O
providing	O
C++	O
with	O
list-comprehension	O
constructs/syntax	O
similar	O
to	O
the	O
set	B-Language
builder	I-Language
notation	I-Language
.	O
</s>
<s>
In	O
Boost	B-Language
.	O
</s>
<s>
With	O
this	O
library	O
,	O
the	O
original	O
Haskell	B-Language
example	O
would	O
look	O
like	O
(	O
using	O
Boost.Lambda	O
for	O
anonymous	O
filtering	O
and	O
transforming	O
functions	O
)	O
(	O
)	O
:	O
</s>
<s>
It	O
's	O
not	O
threadsafe	B-Operating_System
,	O
however	O
.	O
</s>
