Partial function application: Difference between revisions

m
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 1,741:
 
=={{header|Phix}}==
Phix does not explicitly support this, but you can easily emulate it with routine_id<br>
<lang Phix>function fs(integer rid, sequence s)
for i=1 to length(s) do
s[i] = call_func(rid,{(s[i]})
end for
return s
end function
 
function p_apply(sequence f, sequence args)
integer {f1,f2} = f
return call_funcf1(f[1],{f[2]f2,args})
end function
 
function f1(integer i)
return i+i
end function
 
function f2(integer i)
return i*i
end function
 
?p_apply(fsf1{fs,f1},{0,1,2,3})
constant fsf1 = {routine_id("fs"),routine_id("f1")},
?p_apply(fsf2{fs,f2},{2,4,6,8})</lang>
fsf2 = {routine_id("fs"),routine_id("f2")}
 
?p_apply(fsf1,{0,1,2,3})
?p_apply(fsf2,{2,4,6,8})</lang>
{{out}}
<pre>
Line 1,771 ⟶ 1,769:
{4,16,36,64}
</pre>
Should you want to provide the first few arguments set as part of fsf1/2 [ie as a 3rd sequence element]f, then obviously p_apply might be more like
<lang Phix>function p_apply(sequence ffsaffa, sequence extra_args)
objectinteger {faf1,fx,set_argsf2} = ffsaffa
return call_funcf1(faf2,{fx,set_argsffa[3]&extra_args})
end function</lang>
 
7,815

edits