user
A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a *set comprehension*, hence the name.

Some attributes of a list comprehension are:

1. They should be distinct from (nested) for loops and the use of map and filter functions within the syntax of the language.
2. They should return either a list or an iterator (something that returns successive members of a collection, in order).
3. The syntax has parts corresponding to that of set-builder notation.

Task

Write a list comprehension that builds the list of all Pythagorean triples with elements between   **1**   and   **n**.

If the language has multiple ways for expressing such a construct (for example, direct list comprehensions and generators), write one example for each.
assistant
(formerly Perl 6)
Raku has single-dimensional list comprehensions that fall out naturally from nested modifiers; multidimensional comprehensions are also supported via the cross operator; however, Raku does not (yet) support multi-dimensional list comprehensions with dependencies between the lists, so the most straightforward way is currently:

```
my $n = 20;
say gather for 1..$n -> $x {
         for $x..$n -> $y {
           for $y..$n -> $z {
             take $x,$y,$z if $x*$x + $y*$y == $z*$z;
           }
         }
       }

```

Output:

```
((3 4 5) (5 12 13) (6 8 10) (8 15 17) (9 12 15) (12 16 20))
```

Note that gather/take is the primitive in Raku corresponding to generators or coroutines in other languages. It is not, however, tied to function call syntax in Raku. 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.