List comprehensions: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(→Insitux: implementation) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 21:
{{trans|Python}}
{{out}}
Line 275:
end mReturn</syntaxhighlight>
{{Out}}
<
=={{header|Arturo}}==
Line 397:
C doesn't have a built-in syntax for this, but any problem can be solved if you throw enough macros at it:
{{works with|GCC}}
The program below is C11 compliant. For C99 compilers note the change on line 57
for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); }▼
int i;▼
<syntaxhighlight lang="c">
#include <stdlib.h>
Line 464 ⟶ 455:
List * intRangeList(int f, int t) {
List * l = listNew(sizeof f, &f), * e = l;
for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); } // C11 compliant
▲//int i;
return l;
}
Line 611 ⟶ 604:
[x, y, z]
))
console.dir pyth 20</syntaxhighlight>
▲<code>pyth</code> can also be written more concisely as
▲<syntaxhighlight lang="coffeescript">pyth = (n) -> flatten (flatten ([x, y, z] for z in [y..n] when x*x + y*y is z*z for y in [x..n]) for x in [1..n])</syntaxhighlight>
=={{header|Common Lisp}}==
Line 1,057 ⟶ 1,048:
y (range x n+1)
z (range y n+1)
(
(continue))
[x y z]))
Line 2,716 ⟶ 2,707:
=={{header|Wren}}==
Using a generator.
<syntaxhighlight lang="
(1..n-2).each { |x|
(x+1..n-1).each { |y|
|