RosettaCodeData/Task/Apply-a-callback-to-an-array/Phix/apply-a-callback-to-an-arra...

14 lines
285 B
Plaintext

function apply(integer f, sequence s)
-- apply function f to all elements of sequence s
for i = 1 to length(s) do
s[i] = call_func(f, {s[i]})
end for
return s
end function
function add1(integer x)
return x + 1
end function
? apply(routine_id("add1"),{1,2,3})