List comprehensions: Difference between revisions
Content added Content deleted
(→{{header|Picat}}: Split into subsections.) |
|||
Line 1,775: | Line 1,775: | ||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
===List comprehensions=== |
|||
<lang Picat>pyth(N) = [[A,B,C] : A in 1..N, B in A..N, C in B..N, A**2 + B**2 == C**2].</lang> |
<lang Picat>pyth(N) = [[A,B,C] : A in 1..N, B in A..N, C in B..N, A**2 + B**2 == C**2].</lang> |
||
===Array comprehensions=== |
|||
Picat also has array comprehensions. Arrays are generally used for faster access (using <code>{}</code> instead of <code>[]</code>). |
|||
<lang Picat>pyth(N) = {{A,B,C} : A in 1..N, B in A..N, C in B..N, A**2 + B**2 == C**2}.</lang> |
<lang Picat>pyth(N) = {{A,B,C} : A in 1..N, B in A..N, C in B..N, A**2 + B**2 == C**2}.</lang> |
||
===findall/2=== |
|||
A related construct is findall/2 to get all solutions for the specific goal at the second parameter. Here this is shown with member/2 for generating the numbers to test (which for this task is fairly inefficient). |
A related construct is <code>findall/2</code> to get all solutions for the specific goal at the second parameter. Here this is shown with <code>member/2</code> for generating the numbers to test (which for this task is fairly inefficient). |
||
<lang>pyth(N) = findall([A,B,C], (member(A,1..N), member(B,1..N), member(C,1..N), A < B, A**2 + B**2 == C**2)).</lang> |
<lang>pyth(N) = findall([A,B,C], (member(A,1..N), member(B,1..N), member(C,1..N), A < B, A**2 + B**2 == C**2)).</lang> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |