Jump to content

Partial function application: Difference between revisions

(→‎{{header|LFE}}: Added LFE implementation)
Line 1,208:
# fsf2 [2; 4; 6; 8];;
- : int list = [4; 16; 36; 64]</lang>
 
=={{header|Oforth}}==
 
Oforth does not return functions, just blocks. So it can't return partial functions. One way is to create a function that return a closure :
 
<lang Oforth>func: partial(f, p) { #[ p f perform ] }
 
func: fs(f, s) { s map(f) }
func: f1(n) { n 2 * }
func: f2(n) { n sq }
 
func: testPartial
{
| fsf1 fsf2 |
 
partial(#fs, #f1) ->fsf1
partial(#fs, #f2) ->fsf2
 
[ 0, 1, 2, 3 ] fsf1 perform println
[ 0, 1, 2, 3 ] fsf2 perform println
[ 2, 4, 6, 8 ] fsf1 perform println
[ 2, 4, 6, 8 ] fsf2 perform println
}</lang>
 
{{out}}
<pre>
[0, 2, 4, 6]
[0, 1, 4, 9]
[4, 8, 12, 16]
[4, 16, 36, 64]
</pre>
 
=={{header|Order}}==
1,015

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.