Re: [stack] rewriting + second order vs. higher order expressivity
John Nowak <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
Slava has given an interesting example that has made me rethink
getting rid of the n-ary 'map' functional:
Given an array like {1, f, f, f, 2, f, f, 3, 4, f}, turn it
into {1, 1, 1, 1, 2, 2, 2, 3, 4, 4}.
This sort of thing is easy to do with a fold. However, if you want to
avoid generating a new array, it seems that you *need* an n-ary map
combinator that works as such:
{$x0, $x1, ... $xN} map($F) =
null $x0 $F cons $x1 $F cons ... $xN $F cons
Of course, given that we're dealing with arrays, 'map' wouldn't
*actually* be consing and could avoid the generation of another array.
Of course, we're also assuming the array is singly referenced so that
it can be modified in place without visible mutation (which can be
enforced on the type level in 5th).
If we were to write 'map-with' using this n-ary 'map' in C2R, we could
manage to avoid the ugly 'over's of the C2 version and still be able
to reduce each list item independently:
{$x0, $x1, ... $xN} $a map-with($F) =
null $x0 $a $F cons $x1 $a $F cons ... $xN $a $F cons
Interesting. I guess 'map 'should remain n-ary and an n-ary fold
(called 'each' in Factor) should be included as well.
- John