Partial function application: Difference between revisions
Content added Content deleted
(Added Wren) |
(Added Quackery.) |
||
Line 1,867: | Line 1,867: | ||
print fsf1(1, 2, 3, 4) |
print fsf1(1, 2, 3, 4) |
||
print fsf2(1, 2, 3, 4)</lang> |
print fsf2(1, 2, 3, 4)</lang> |
||
=={{header|Quackery}}== |
|||
(It would be more natural in Quackery to take the arguments to ''fs'' in the order ''s f''. This code complies with the requirements of the task. To make it idiomatic, omit all but the second ''swap''.) |
|||
<lang Quackery> [ [] unrot |
|||
swap nested |
|||
' join nested |
|||
join nested |
|||
' witheach nested |
|||
swap join |
|||
do ] is fs ( f s --> [ ) |
|||
[ 2 * ] is f1 ( n --> n ) |
|||
[ 2 ** ] is f2 ( n --> n ) |
|||
[ ' f1 swap fs ] is fsf1 ( s --> [ ) |
|||
[ ' f2 swap fs ] is fsf2 ( s --> [ ) |
|||
' [ 0 1 2 3 ] fsf1 echo cr |
|||
' [ 0 1 2 3 ] fsf2 echo cr |
|||
' [ 2 4 6 8 ] fsf1 echo cr |
|||
' [ 2 4 6 8 ] fsf2 echo cr |
|||
( ... or, using Quackery's partial applicator "witheach" ... ) |
|||
cr |
|||
' [ [ 0 1 2 3 ] [ 2 4 6 8 ] ] |
|||
witheach |
|||
[ dup ' [ fsf1 fsf2 ] |
|||
witheach [ do echo cr ] ]</lang> |
|||
{{Out}} |
|||
<pre>[ 0 2 4 6 ] |
|||
[ 0 1 4 9 ] |
|||
[ 4 8 12 16 ] |
|||
[ 4 16 36 64 ] |
|||
[ 0 2 4 6 ] |
|||
[ 0 1 4 9 ] |
|||
[ 4 8 12 16 ] |
|||
[ 4 16 36 64 ]</pre> |
|||
=={{header|R}}== |
=={{header|R}}== |