Re: [stack] Combining Combinators

"kuwabatake" <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
> At level one there are functions which take zero level entities
> as arguments. At level two there are combinators which take
> level one entities as arguments but cannot take level zero
> entities as arguments. Examples: dip, nullary, map, filter, fold.
> At level three there would be functions which take level two
> entities as arguments but cannot take level one entities as
> arguments.

Interesting.

I propose a function called `compose'. It takes a quoted combinator
[C1] and alters that combinator to expect TWO functions on top of the
stack, compose them, and then execute C1.

For example:
[1 2 3] [2 *] [1 +] [map] compose i
=> [3 5 7]
['a] 123 ['b] [cons] [dip] compose i
=> ['a 'b]

This can be written in Joy as follows:
compose == [concat] swap concat

Note that applying compose to a non-combinator is not `meaningful':
[+] compose
=> [concat +]
it results in the meaningless function [concat +] which will throw an
error no matter what kind of input you give it.

I think we can construct other third- and even higher-level functions
using a similar technique. Of course, they are all really functions
stack->stack at heart; the distinction comes with the fact that
third-level functions only make sense when they modify second-level
functions (combinators).

~Daniel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.