24 lines
613 B
Text
24 lines
613 B
Text
-- demo\rosetta\List_comprehensions.exw
|
|
with javascript_semantics
|
|
function list_comprehension(sequence s, integer rid, k, level=1, sequence args={})
|
|
sequence res = {}
|
|
args &= 0
|
|
for i=1 to length(s) do
|
|
args[$] = s[i]
|
|
if level<k then
|
|
res &= list_comprehension(s,rid,k,level+1,deep_copy(args))
|
|
else
|
|
res &= call_func(rid,args)
|
|
end if
|
|
end for
|
|
return res
|
|
end function
|
|
|
|
function triangle(integer a, b, c)
|
|
if a<b and a*a+b*b=c*c then
|
|
return {{a,b,c}}
|
|
end if
|
|
return {}
|
|
end function
|
|
|
|
?list_comprehension(tagset(20),triangle,3)
|