ALGOL 68 does not have list comprehension, however it is sometimes reasonably
generous about where a flex array is declared. And with the addition
of an append operator "+:=" for lists they can be similarly manipulated.

AppleScript does not provide built-in notation for list comprehensions. The list monad pattern which underlies list comprehension notation can, however, be used in any language which supports the use of higher order functions and closures. AppleScript can do that, although with limited elegance and clarity, and not entirely without coercion.

Bracmat does not have built-in list comprehension, but nevertheless there is a solution for fixed n that does not employ explicit loop syntax. By their positions in the pattern and the monotonically increasing values in the subject, it is guaranteed that x always is smaller than y and that y always is smaller than z. The combination of flags %@ ensures that x, y and z pick minimally one (%) and at most one (@) element from the subject list.

Either GCC's "statement expressions" extension, or a minor piece of undefined behaviour, are required for this to work (technically setjmp, which powers the non-GCC version, isn't supposed to be part of a comma expression, but almost all compilers will treat it as intended). Variables used by one of these looping expressions should be declared volatile to prevent them from being modified by setjmp.

The list implementation in this example is a) terrible and b) leaks memory, neither of which are important to the example. In reality you would want to combine any lists being generated in expressions with an automatic memory management system (GC, autorelease pools, something like that).

Icon's (and Unicon's) natural goal-directly evaluation produces result
sequences and can be used to form list comprehensions. For example, the
expression:

|(x :=seq(), x^2>3, x*2)

is capable of producing successive elements from the infinite list described in the
Wikipedia article. For example, to produce the first 100 elements:

procedure main()everywrite(|(x :=seq(), x^2>3, x*2)\100end

While result sequences are lexically bound to the code that describes them,
that code can be embedded in a co-expression to allow access to the result
sequence throughout the code. So Pythagorean triples can be produced
with (works in both languages):

ES5 does not provide built-in notation for list comprehensions. The list monad pattern which underlies list comprehension notation can, however, be used in any language which supports the use of higher order functions. The following shows how we can achieve the same result by directly using a list monad in ES5, without the abbreviating convenience of the syntactic sugar which is helpfully introduced in ES6.

// USING A LIST MONAD DIRECTLY, WITHOUT SPECIAL SYNTAX FOR LIST COMPREHENSIONS

function triples(n){return[[x,y,z]for each (x in range(1,n+1))for each (y in range(x,n+1))for each (z in range(y,n+1))if(x*x + y*y == z*z)]}

for each (var triple in triples(20)) print(triple);

outputs:

3,4,5
5,12,13
6,8,10
8,15,17
9,12,15
12,16,20

List comprehension notation was not, in the end, included in the final ES6 standard, and the code above will not run in fully ES6-compliant browsers, but we can still go straight to the underlying monadic logic of list comprehensions and obtain:

[(x,y,z) | x <- [1..n], y <- [x..n], z <- [y..n], x^2 + y^2 == z^2]

by using concatMap / flatMap (the monadic bind function for lists), and x => [x] (monadic return for lists):

This code uses the select() function, which was added in PARI version 2.4.2. The order of the arguments changed between versions; to use in 2.4.2 change select(function, vector) to select(vector, function).

map binds $_ to each element of the input list and collects the results from the block. grep returns every element of the input list for which the block returns true. The .. operator generates a list of numbers in a specific range.

Perl 6 has single-dimensional list comprehensions that fall out naturally from nested modifiers; multidimensional comprehensions are also supported via the cross operator; however, Perl 6 does not (yet) support multi-dimensional list comprehensions with dependencies between the lists, so the most straightforward way is currently:

Note that gather/take is the primitive in Perl 6 corresponding to generators or coroutines in other languages. It is not, however, tied to function call syntax in Perl 6. We can get away with that because lists are lazy, and the demand for more of the list is implicit; it does not need to be driven by function calls.

There is no elegant way to comprise a list from multiple variables. Pythagorean triplets need three variables, with 1..n giving x, then x..n giving y, then y..n giving z. A less than elegant way is to nest three blocks.

Ruby 1.9.2 introduces two new methods: Enumerable#flat_map joins all the arrays from the block. Array#keep_if is an alternative to Enumerable#select that modifies the original array. (We avoid Array#select! because it might not return the array.)

The [[x, y, z]].keep_if { ... } returns either an array of one Pythagorean triplet, or an empty array.

The inner (y..n).flat_map { ... } concatenates those arrays for all z given some x, y.

The middle (x..n).flat_map { ... } concatenates the inner arrays for all y given some x.

The outer (1..n).flat_map { ... } concatenates the middle arrays for all x.

Alas, the type of collection returned depends on the type of the collection
being comprehended. In the example above, we are comprehending a Range.
Since a Range of triangles doesn't make sense, it returns the
closest (supertype) collection for which it does, an IndexedSeq.