List comprehensions: Difference between revisions

Added Factor
(Updated Java code to use IntStreams to do the list comprehension bit. Technically cleaner, but still clunky.)
(Added Factor)
Line 732:
for c in [b..n] do
if (a*a+b*b = c*c) then yield (a,b,c)]</lang>
 
=={{header|Factor}}==
Factor does not support list comprehensions by default. The <code>backtrack</code> vocabulary can make for a faithful imitation, however.
<lang factor>USING: backtrack kernel locals math math.ranges ;
 
:: pythagorean-triples ( n -- seq )
[
n [1,b] amb-lazy :> a
a n [a,b] amb-lazy :> b
b n [a,b] amb-lazy :> c
a a * b b * + c c * = must-be-true { a b c }
] bag-of ;</lang>
 
=={{header|Fortran}}==
1,808

edits