26 lines
660 B
Text
26 lines
660 B
Text
--
|
|
-- demo\rosetta\List_comprehensions.exw
|
|
-- ====================================
|
|
--
|
|
function list_comprehension(sequence s, integer rid, integer nargs, integer level=1, sequence args={})
|
|
sequence res = {}
|
|
args &= 0
|
|
for i=1 to length(s) do
|
|
args[$] = s[i]
|
|
if level<nargs then
|
|
res &= list_comprehension(s,rid,nargs,level+1,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),routine_id("triangle"),3)
|