Higher-order functions: Difference between revisions
Content added Content deleted
m (→{{header|Quackery}}: clarification) |
(→{{header|Quackery}}: replaced my previous solution with one that defines map and filter in terms of fold) |
||
Line 3,523: | Line 3,523: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
First define the higher order functions <code> |
First define the higher order functions <code>fold</code>, <code>map</code>, and <code>filter</code>. |
||
<pre> [ stack ] |
<pre> [ stack ] is fold.act ( --> s ) |
||
protect map.act |
|||
[ map.act put |
|||
[] swap witheach |
|||
[ map.act share do |
|||
⚫ | |||
⚫ | |||
⚫ | |||
protect filter.act |
|||
[ filter.act put |
|||
[] swap witheach |
|||
⚫ | |||
filter.act share do |
|||
⚫ | |||
⚫ | |||
filter.act release ] is filter ( [ x --> [ ) |
|||
[ stack ] is fold.act ( --> s ) |
|||
protect fold.act |
protect fold.act |
||
Line 3,553: | Line 3,533: | ||
witheach |
witheach |
||
[ fold.act share do ] ] |
[ fold.act share do ] ] |
||
fold.act release ] is fold |
fold.act release ] is fold ( [ x --> x ) |
||
[ ' [ [ ] ] rot join swap |
|||
⚫ | |||
nested |
|||
⚫ | |||
⚫ | |||
[ ' [ [ ] ] rot join swap |
|||
⚫ | |||
nested ' dup swap join |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
... ' reverse map |
... ' reverse map |
||
... witheach [ echo$ sp ] |
... witheach [ echo$ sp ] |
||
Line 3,569: | Line 3,570: | ||
... |
... |
||
[ 42 23 ] |
[ 42 23 ] |
||
Stack empty. |
Stack empty.</pre> |
||
⚫ | |||
... [ dup |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|R}}== |
=={{header|R}}== |