List comprehensions: Difference between revisions

→‎{{header|Picat}}: Split into subsections.
(→‎{{header|Picat}}: Split into subsections.)
Line 1,775:
 
=={{header|Picat}}==
Picat has list===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>
 
===Array comprehensions===
asPicat wellalso ashas 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>
 
===findall/2===
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>
 
 
 
=={{header|PicoLisp}}==
495

edits