List comprehensions: Difference between revisions
Content added Content deleted
(→Perl: new example) |
(→TI-89 BASIC: new example) |
||
Line 187: | Line 187: | ||
puts [lcomp {$x $y $z} x $range y $range z $range {$x < $y && $x**2 + $y**2 == $z**2}]</lang> |
puts [lcomp {$x $y $z} x $range y $range z $range {$x < $y && $x**2 + $y**2 == $z**2}]</lang> |
||
<pre>{3 4 5} {5 12 13} {6 8 10} {8 15 17} {9 12 15} {12 16 20}</pre> |
<pre>{3 4 5} {5 12 13} {6 8 10} {8 15 17} {9 12 15} {12 16 20}</pre> |
||
=={{header|TI-89 BASIC}}== |
|||
TI-89 BASIC does not have a true list comprehension, but it has the seq() operator which can be used for some similar purposes. |
|||
{1, 2, 3, 4} → a |
|||
seq(a[i]^2, i, 1, dim(a)) |
|||
produces {1, 4, 9, 16}. When the input is simply a numeric range, an input list is not needed; this produces the same result: |
|||
seq(x^2, x, 1, 4) |