List comprehensions: Difference between revisions

Content added Content deleted
(adding GAP)
(Add scheme)
Line 745: Line 745:
scala> pythagoranTriangles(21)
scala> pythagoranTriangles(21)
res36: List[(Int, Int, Int)] = List((3,4,5), (5,12,13), (6,8,10), (8,15,17), (9,12,15), (12,16,20))
res36: List[(Int, Int, Int)] = List((3,4,5), (5,12,13), (6,8,10), (8,15,17), (9,12,15), (12,16,20))
</pre>

=={{header|Scheme}}==
Scheme has no native list comprehensions, but SRFI-42 provides them:

<lang scheme>
(list-ec (:range x 1 21)
(:range y x 21)
(:range z y 21)
(if (= (* z z) (+ (* x x) (* y y))))
(list x y z))
</lang>

<pre>
((3 4 5) (5 12 13) (6 8 10) (8 15 17) (9 12 15) (12 16 20))
</pre>
</pre>